PHP tag in database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Subhash

    #1

    PHP tag in database

    Hello,
    I have a database that consists of text. This text contains php code
    that needs to be processed before echoing it on the browser. A
    pseudocode may be:

    <?php
    /* connect to database */

    /* for each record
    process the php text in database */
    ?>

    Simply echoing the text will not make the php tags to be processed.
    Please let me know if you have any ideas or opinions on how to make
    the text information in database to be processed.

    Thanks!
  • Kevin Thorpe

    #2
    Re: PHP tag in database

    Subhash wrote:
    [color=blue]
    > Hello,
    > I have a database that consists of text. This text contains php code
    > that needs to be processed before echoing it on the browser. A
    > pseudocode may be:
    >
    > <?php
    > /* connect to database */
    >
    > /* for each record
    > process the php text in database */
    > ?>
    >
    > Simply echoing the text will not make the php tags to be processed.
    > Please let me know if you have any ideas or opinions on how to make
    > the text information in database to be processed.[/color]

    Look up eval (but be VERY careful what you execute, don't let anyone
    else write it to your database)

    Comment

    • Subhash

      #3
      Re: PHP tag in database

      Kevin Thorpe <kevin@pricetra k.com> wrote in message news:<40507c46$ 0$16368$afc38c8 7@news.easynet. co.uk>...[color=blue]
      > Subhash wrote:
      >[color=green]
      > > Hello,
      > > I have a database that consists of text. This text contains php code
      > > that needs to be processed before echoing it on the browser. A
      > > pseudocode may be:
      > >
      > > <?php
      > > /* connect to database */
      > >
      > > /* for each record
      > > process the php text in database */
      > > ?>
      > >
      > > Simply echoing the text will not make the php tags to be processed.
      > > Please let me know if you have any ideas or opinions on how to make
      > > the text information in database to be processed.[/color]
      >
      > Look up eval (but be VERY careful what you execute, don't let anyone
      > else write it to your database)[/color]

      Thanks Kevin. Thats really helped. But what if the text was something
      like this:

      <htmlcode>Bla h Blah</htmlcode>
      <?php echo "xyz"; ?>
      <htmlcode>Bla h Blah</htmlcode>

      When you do an eval on this it does not work, which is correct. Is
      there anyway to properly handle the above case?

      Comment

      • Pedro Graca

        #4
        Re: PHP tag in database

        Subhash wrote:[color=blue]
        > what if the text was something like this:
        >
        ><htmlcode>Bl ah Blah</htmlcode>
        ><?php echo "xyz"; ?>
        ><htmlcode>Bl ah Blah</htmlcode>
        >
        > When you do an eval on this it does not work, which is correct. Is
        > there anyway to properly handle the above case?[/color]

        I'd try:

        <?php
        $text = '<htmlcode>Bla h Blah</htmlcode>
        <?php echo "xyz"; ?>
        <htmlcode>Bla h Blah</htmlcode>';

        eval('?>' . $text);
        ?>
        --
        --= my mail box only accepts =--
        --= Content-Type: text/plain =--
        --= Size below 10001 bytes =--

        Comment

        • Ken Robinson

          #5
          Re: PHP tag in database

          subhash_daga@ya hoo.com (Subhash) wrote in
          news:fdffa0fb.0 403111101.725cf f83@posting.goo gle.com:
          [color=blue]
          > Kevin Thorpe <kevin@pricetra k.com> wrote in message
          > Thanks Kevin. Thats really helped. But what if the text was something
          > like this:
          >
          > <htmlcode>Bla h Blah</htmlcode>
          > <?php echo "xyz"; ?>
          > <htmlcode>Bla h Blah</htmlcode>
          >
          > When you do an eval on this it does not work, which is correct. Is
          > there anyway to properly handle the above case?[/color]

          How about ... write your data to a temp file and then include that file.

          Ken Robinson

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: PHP tag in database

            subhash_daga@ya hoo.com (Subhash) wrote in message news:<fdffa0fb. 0403111101.725c ff83@posting.go ogle.com>...[color=blue]
            > Kevin Thorpe <kevin@pricetra k.com> wrote in message news:<40507c46$ 0$16368$afc38c8 7@news.easynet. co.uk>...[color=green]
            > > Subhash wrote:
            > >[color=darkred]
            > > > Hello,
            > > > I have a database that consists of text. This text contains php code
            > > > that needs to be processed before echoing it on the browser. A
            > > > pseudocode may be:
            > > >
            > > > <?php
            > > > /* connect to database */
            > > >
            > > > /* for each record
            > > > process the php text in database */
            > > > ?>
            > > >
            > > > Simply echoing the text will not make the php tags to be processed.
            > > > Please let me know if you have any ideas or opinions on how to make
            > > > the text information in database to be processed.[/color]
            > >
            > > Look up eval (but be VERY careful what you execute, don't let anyone
            > > else write it to your database)[/color]
            >
            > Thanks Kevin. Thats really helped. But what if the text was something
            > like this:
            >
            > <htmlcode>Bla h Blah</htmlcode>
            > <?php echo "xyz"; ?>
            > <htmlcode>Bla h Blah</htmlcode>
            >
            > When you do an eval on this it does not work, which is correct. Is
            > there anyway to properly handle the above case?[/color]

            Look at the user notes <http://in2.php.net/eval> especially
            eval_html()

            --
            "I don't believe in the God who doesn't give me food, but shows me
            heaven!"--Swami Vivekanandha
            Email: rrjanbiah-at-Y!com

            Comment

            • Subhash

              #7
              Re: PHP tag in database

              Thanks guys, all your suggestions worked great! Thanks, Subhash

              Comment

              • Subhash

                #8
                Re: PHP tag in database

                Pedro Graca <hexkid@hotpop. com> wrote in message news:<c2ql6i$21 5ia5$3@ID-203069.news.uni-berlin.de>...[color=blue]
                > Subhash wrote:[color=green]
                > > what if the text was something like this:
                > >
                > ><htmlcode>Bl ah Blah</htmlcode>
                > ><?php echo "xyz"; ?>
                > ><htmlcode>Bl ah Blah</htmlcode>
                > >
                > > When you do an eval on this it does not work, which is correct. Is
                > > there anyway to properly handle the above case?[/color]
                >
                > I'd try:
                >
                > <?php
                > $text = '<htmlcode>Bla h Blah</htmlcode>
                > <?php echo "xyz"; ?>
                > <htmlcode>Bla h Blah</htmlcode>';
                >
                > eval('?>' . $text);
                > ?>[/color]

                Pedro,
                Your suggestion worked great! But I don't understand how? I mean how
                does adding '?>' to the $text make it work?

                Thanks

                Comment

                • Pedro Graca

                  #9
                  Re: PHP tag in database

                  Subhash wrote:[color=blue]
                  > Pedro Graca <hexkid@hotpop. com> wrote in message news:<c2ql6i$21 5ia5$3@ID-203069.news.uni-berlin.de>...[color=green]
                  >> eval('?>' . $text);[/color][/color]
                  [color=blue]
                  > Your suggestion worked great! But I don't understand how? I mean how
                  > does adding '?>' to the $text make it work?[/color]

                  The '?>' simply says to php:

                  - Hey! Quit "PHP mode" and evaluate what follows as HTML, parsing
                  whatever you find between <?php and ?> as PHP.

                  :)
                  --
                  --= my mail box only accepts =--
                  --= Content-Type: text/plain =--
                  --= Size below 10001 bytes =--

                  Comment

                  Working...