PDA

View Full Version : Use php in an echo?


Nightfire
12-05-2002, 08:39 PM
Might seem simple enough, but I'm having some problems with this. I'm adding everything from the database into a variable called $content, like this:


$content = '<b>'.$row[title].'</b><br>'.$row[content];

then echo'ing it on a page (<?=$content?>) where I want it. The problem is that I'm trying to get some php code in $row[content] to be parsed, but it is just simply printing it onto the page, as if it was text.

Any ideas how to do this?

firepages
12-05-2002, 08:49 PM
<?
$content = '<b>'.$row[title].'</b><br>'.$row[content];
eval('echo $content;');
?>


the single quotes in the eval() are important .

Nightfire
12-05-2002, 09:14 PM
Thanks :) I ended up going with

$content = addslashes($content);
eval("\$content = \"$content\";");
$content = stripslashes($content);

echo $content;

Works perfectly :)