dbx Posted November 6, 2008 Share Posted November 6, 2008 I'm storing text in a database and I want to include PHP code in the text. E.g. I store the following in the table: "blah blah blah blah blah <?php echo "hello"; ?> blah blah blah" When my script gets the text from the DB and displays it in the browser, nothing shows up where <?php echo "hello"; ?> is. Could someone please tell me how I should be doing it? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/ Share on other sites More sharing options...
ratcateme Posted November 6, 2008 Share Posted November 6, 2008 try eval("\$text= \"{$db_text}\"';"); Scott. Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683478 Share on other sites More sharing options...
dbx Posted November 6, 2008 Author Share Posted November 6, 2008 Thanks for that. eval("\$text = \"$db_text\";"); will print out a string. it doesn't seem to like functions though. $db_text = "blah blah <?php con("123"); ?> blah"; doesn't work. Do you have to use something different for functions? Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683485 Share on other sites More sharing options...
ratcateme Posted November 6, 2008 Share Posted November 6, 2008 where is con() defined i haven't used eval with functions before sorry. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683494 Share on other sites More sharing options...
dbx Posted November 6, 2008 Author Share Posted November 6, 2008 con() is a function I made. it is included in the <head> section along with some other things Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683496 Share on other sites More sharing options...
ratcateme Posted November 6, 2008 Share Posted November 6, 2008 is it a javascript function? can you give us some summarized code with all the important bits. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683500 Share on other sites More sharing options...
dbx Posted November 6, 2008 Author Share Posted November 6, 2008 it's a PHP currency converter it takes the value, checks what currency the user has chosen, does the conversion, formats the result and displays it on the page. if this can't be done, it's not a problem. it was just a minor improvement rather than a necessity. i'm not going to modify functions or create new ones to do it. Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683509 Share on other sites More sharing options...
ratcateme Posted November 6, 2008 Share Posted November 6, 2008 how are you including it? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683510 Share on other sites More sharing options...
Adam Posted November 6, 2008 Share Posted November 6, 2008 Unless the functions print straight to the page, you made need to echo out the return value of "con()" .. Also don't forget you've got qutoes in there which will trigger an error: $db_text = "blah blah <?php echo con(\"123\"); ?> blah"; Adam Quote Link to comment https://forums.phpfreaks.com/topic/131596-echo-text-that-includes-php-code-from-database/#findComment-683511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.