SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing Text from a Database before Outputting… It is possible?

    Hi, this is probably such a dumb question with a huge “whaa?” or “can’t be done” answer but I need to ask it anyway.

    I’ve written a script that has regular text inputted into a mysql database. Based on certain variables certain text from the database is selected when needed and outputted to a webpage. The thing is, is I would like this text in the database to contain variables ($foo this $bar that) but as far as I can tell, when I select information from a database and send it to a webpage it never gets parsed and <?=$foo?> tags appear in the outputted html.

    Is there any way to parse information coming out of a database before outputted to a webpage?

    Thanks.

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but you have to make sure that those variables exist, anyway, look at eval.

  3. #3
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Eval works on variables but what about more complex PHP? What if I take it one step further and the text in my database reads:

    HTML Code:
    Blah Blah Blah HTML code here!<br> 
    <?php
    echo "BLAH PHP!";
    ?>
    How do I parse this from a database outputting to an HTML page?

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eval works on PHP code. You could even feed a complete PHP script to it, not that it would make any sense.

  5. #5
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Gaheris, I looked a little deeper and found that
    PHP Code:
     eval("?".chr(62).$text.chr(60)."?"); 
    does what I was asking about. Anyone searching for the same thing can use the code above.

  6. #6
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that makes PHP (in the eval call) 'leave' PHP mode so that you can parse normal files which for example contain markup.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •