|
Posted by J.O. Aho on 03/06/06 07:20
a wrote:
> "J.O. Aho" <user@example.net> wrote in message
> news:471robFde4e0U1@individual.net...
>> a wrote:
>>> I've been storing some html data in a mysql database and creating
>>> webpages based on that code using a simple "echo $html" type command. I
>>> have some php code sprinked in and noticed that php doesn't execute this
>>> code, it just prints it. After reading some more about it, i found out
>>> you have to use eval() to execute a string of php code. My problem is
>>> that there is html/php code. is there a way to "execute" the html code
>>> along /w the php code, or somehow seperate it, so only php code gets the
>>> eval() function?
>> Yes you can, there is two ways
>>
>> --- code 1 ---
>> <?PHP
>> $code="echo \"test\n\"; ?> <h1>hello</h1> <?PHP echo \"test2\n\"; ";
>>
>> eval($code);
>>
>> ?>
>> --- eof ---
>>
>>
>> --- code 2---
>> <?PHP
>> $code="echo \"test\n\"; echo \"<h1>hello</h1>\"; echo \"test2\n\"; ";
>>
>> eval($code);
>>
>> ?>
>> --- eof ---
>>
>
> Cool this seems to be working. I added a few lines to decide if the stored
> code starts w/ php or html. I add a '?>' to the beginning of html code to
> turn off the php and the same at the end. Seems to be working with html
> only code!
You could make a new function
function eval2($code) {
eval('?>' . $code . '<?PHP');
}
This way eval2() should take the code as it usually looks in a PHP file.
<?PHP
$code="echo \"test\n\"; ?> <h1>hello</h1> <?PHP echo \"test2\n\"; ";
eval($code);
?>
would become
<?PHP
$code="<?PHP echo \"test\n\"; ?> <h1>hello</h1> <?PHP echo \"test2\n\"; ?>";
eval2($code);
?>
(I haven't tested this one, but in theory it should work).
//Aho
Navigation:
[Reply to this message]
|