Re: how do I use "<" and "&lt" with eval()?

From: Date: Thu, 01 Nov 2001 08:28:03 +0000
Subject: Re: how do I use "<" and "&lt" with eval()?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-73123@lists.php.net to get a copy of this message
----- Original Message ----- From: "John A. Grant" <jazrant@zsc.nrcan.zc.ca> To: <php-general@lists.php.net> Sent: Wednesday, October 31, 2001 11:51 PM Subject: [PHP] how do I use "<" and "&lt" with eval()? > I'm not having an easy time understanding the discussion > in the doc for eval(). > > I want to read this string from a file: > xxx <?php somefunc("yyy",3); ?> zzz > > and then "run" it. > > I tried this code: > <?php > function somefunc($text,$n) > { > for($i=0;$i<$n;$i++){ > echo $text; > } > } > $string='xxx <?php somefunc("yyy",3); ?> zzz'; > eval($string); > ?> > > but I get > "Parse error: parse error in eval.php(11) : eval()'d code on line 1 > > Do I have to use &lt; and &gt; in place of "<" & ">"? I > tried > several combinations, but I still get the same error. > > -- > John A. Grant * I speak only for myself * (remove 'z' to reply) > Radiation Geophysics, Geological Survey of Canada, Ottawa > If you followup, please do NOT e-mail me a copy: I will read it here > If you do that this way it looks for php like this: <?php function somefunc($text,$n) { for($i=0;$i<$n;$i++){ echo $text; } } #$string='xxx <?php somefunc("yyy",3); ?> zzz'; #eval($string); xxx <?php somfunc("yyy",3); ?> zzz ?> (as someone before correctly stated) As you see, for PHP is some HTML-Code in the php-code-zone. To avoid this, do it that way: <?php function somefunc($text,$n) { for($i=0;$i<$n;$i++){ echo $text; } } $string='xxx <?php somefunc("yyy",3); ?> zzz'; eval("?>$string"); ?> Pay attention to the trailing "?>" in eval. That causes php to change to HTML-Mode within the eval'd code. Hope, I could help you Stefan Rusterholz, s.rusterholz@interaktion.ch ---------------------------------- interaktion gmbh Stefan Rusterholz Zürichbergstrasse 17 8032 Zürich ---------------------------------- T. +41 1 253 19 55 F. +41 1 253 19 56 W3 www.interaktion.ch ----------------------------------

« previous php.general (#73123) next »