Re: Execute string contains php syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

eval will work for any string containing php code. The problem here is 
with the string formed. You should use single quotes (')  instead of 
double quotes (") while declaring the string. Also after $a+$b, there 
should be a semicolon.

So - $string = "$a = 7; $b = 8; $c = $a + $b"; should be  - $string = '$a 
= 15; $b = 25; $c = $a + $b; ';

when you declare with double quotes, the php will automatically eval it. 
evaling it again will be an error.

Regards,
Manda Krishna Srikanth
http://www.krishnasrikanth.com

php-objects@xxxxxxxxxxxxxxx wrote on 10/30/2007 03:48:25 PM:

> Hello everyone,
> 
> I have a string, containing  php syntax, like echoing, variable 
declaration,
> variable assignment, etc
> 
> Is there any php function to execute this string, for example :
> 
> <?
> $string = ?$a = 7; $b = 8; $c = $a + $b?;
> 
> //execute the $string as normal php execution
> echo ?it is $c?; 
> ?>
> 
> Is there any proper replacement to the second line routine? (eval 
function
> in php doesn?t satisfy)
> 
> Thanks
> 
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you




[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux