...

View Full Version : echoing php code



Blaher
02-17-2008, 03:04 PM
Let's say I have the following:
$content="<?php echo 'Hello world\n'; ?>"

and I wanted the php code to run what's inside that variable. How would I be able to do that?


The reason for this is, I'm working on a CMS and if the content in the database contains php, I want it to be ran.

-Thanks in advanced

mlseim
02-17-2008, 03:17 PM
The closest thing I could find was using eval():
http://us3.php.net/eval

Scroll down to the entry dated: 31-Jan-2006

That looks similar to what you're doing.

Blaher
02-17-2008, 03:40 PM
Thanks that works. It won't work of course if I have html code in it (<?php code ?> some html), but I can easily manipulate the string to only eval the php code.

CFMaBiSmAd
02-17-2008, 04:20 PM
The eval() allows closing and opening ?> <?php tags. You can put inline html if you want.

If I remember correctly it assumes you are initially in php "mode", so you must put an initial closing ?> tag if the string starts with inline html.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum