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

From: Date: Wed, 31 Oct 2001 23:40:52 +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-73088@lists.php.net to get a copy of this message
In article <20011031230249.5706.qmail@pb1.pair.com>, jazrant@zsc.nrcan.zc.ca (John A. Grant) wrote: > 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 eval() treats the passed argument as if it were inline PHP code. You're effectively doing this: <?php function somefunc($text,$n) { for($i=0;$i<$n;$i++){ echo $text; } } xxx <?php somefunc("yyy",3); ?> zzz ?> So the extra set of PHP tags is a problem, and xxx and zzz must both be valid code (i.e. terminating statements with semi-colons, concatenating strings with a period...) I'm guessing what you really want is: eval('somefunc("yyy",3);') In that case, you could use a regex to extract the portion of your text string that's enclosed by PHP tags. -- CC

« previous php.general (#73088) next »