Jump to content

echo text that includes php code from database?


Recommended Posts

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

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?

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.