Re: Can PHP execute a string containing PHP code?

[email protected] (Bojan Tesanovic) Fri, 9 May 2008 20:15:17 +0200
Newsgroups php.evangelism
Message-ID <[email protected]>
--Apple-Mail-1-121483921
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed

$toEval = "\$y = 5 * 6; ";
eval($toEval);

echo $y; //will output 30


On May 9, 2008, at 7:41 PM, jim wrote:

> Hi,
>
> Can anyone tell me how to use PHP to execute a string that contains  
> PHP code
> which contains references to objects and variables such that when  
> the string
> (code) is executed the objects and/or variables are updated (from the
> perspective of the calling program)?
>
> I am in the process of determining if PHP is the appropriate scripting
> language for an application that I am writing.
>
> Thanks in advance.
> Jim
>
>

Bojan Tesanovic
http://www.carster.us/





--Apple-Mail-1-121483921
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=ISO-8859-1

<html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
-webkit-line-break: after-white-space; ">
<div>$toEval =3D "\$y =3D 5 * 6; =
";</div><div>eval($toEval);</div><div><br =
class=3D"webkit-block-placeholder"></div><div>echo $y; //will output =
30</div><div><br class=3D"webkit-block-placeholder"></div><br><div><div>On=
 May 9, 2008, at 7:41 PM, jim wrote:</div><br =
class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">Hi,</div><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: =
14px; "><br></div><div style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; ">Can anyone tell me how to use =
PHP to execute a string that contains PHP code<span =
class=3D"Apple-converted-space">=A0</span></div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">which =
contains references to objects and variables such that when the =
string<span class=3D"Apple-converted-space">=A0</span></div><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">(code) is executed the objects and/or variables are =
updated (from the<span class=3D"Apple-converted-space">=A0</span></div><di=
v style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">perspective of the calling program)?</div><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; min-height: 14px; "><br></div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I am in =
the process of determining if PHP is the appropriate scripting<span =
class=3D"Apple-converted-space">=A0</span></div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">language =
for an application that I am writing.</div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; =
min-height: 14px; "><br></div><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Thanks in =
advance.</div><div style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; ">Jim<span =
class=3D"Apple-converted-space">=A0</span></div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; =
min-height: 14px; "><br></div><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: =
14px; "><br></div> </blockquote></div><br><div> <span =
class=3D"Apple-style-span" style=3D"border-collapse: separate; color: =
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
normal; font-variant: normal; font-weight: normal; letter-spacing: =
normal; line-height: normal; orphans: 2; text-align: auto; text-indent: =
0px; text-transform: none; white-space: normal; widows: 2; word-spacing: =
0px; -webkit-border-horizontal-spacing: 0px; =
-webkit-border-vertical-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0; "><span class=3D"Apple-style-span" =
style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
-webkit-border-vertical-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; "><div>Bojan =
Tesanovic</div><div><a =
href=3D"http://www.carster.us">http://www.carster.us</a>/</div><div><br =
class=3D"webkit-block-placeholder"></div></span><br =
class=3D"Apple-interchange-newline"></span><br =
class=3D"Apple-interchange-newline"> </div><br></body></html>=

--Apple-Mail-1-121483921--