SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    retrieving php code from database and have it translate

    im trying to retrieve a php code ( something like <?php echo bla bla ?>) that is save inside a database and have it display on the page

    but all getting is the php code as text like
    <?php echo bla bla ?>

    instead of

    bla bla

    would this be possible to do ?

    thanks

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    run it thought eval();
    http://www.php.net/eval

    But do not run eval on untrusted data!
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.... what about things like forum template variables (such as {AVATAR_IMG} or something) that if written on a .tpl file look fine but when they are retrieved from a database it shows it as plain text instead of the actuall avatar or whatever. would the eval() thing work for that

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Those need to be replaced either with regex or str_replace.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry i have no idea what that is... any links?

    thanks a lot

  6. #6
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay i just quickly read through those on what i found in google and im a little confused on how they could be used to translate template variables

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    well I myself don't have the expertise or the time at this particular moment (busy in the real world) to write up any code for templating. but you will have to look for {AVATAR_IMG} then replace that with the actual data you want.

    PHP Code:
    $s 'My new image {AVATAR_IMG} on display for the world to see.';
    $s str_replace('{AVATAR_IMG}''new data'$s); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  8. #8
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    soooo... okay i sort of got that.... ima try to work something out, but i can see this being a lot more work than i was hoping for.

    but if any other solutions, it would be awesome to hear them.

    thanks

  9. #9
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    There is a better solution. Use an already made templetating engine like Smarty.

    http://smarty.php.net/
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  10. #10
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wait - php code coming out as text - you sure PHP is installed? It might not be...

  11. #11
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    na my problem wasnt really php, it was template variables from my forum, and i thought it could be solved the same way...


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
  •