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

From: Date: Thu, 01 Nov 2001 13:41:05 +0000
Subject: Re: how do I use "<" and "&lt" with eval()?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-73151@lists.php.net to get a copy of this message
"Stefan Rusterholz" <scripting@interaktion.ch> wrote in message news:001001c162af$1fd842f0$3c01a8c0@quasimodo... [...] > 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. Yes, thanks - it works now. I can see that you have to exit php code mode before you encounter HTML 'xxx'. Then you enter php mode, run somefunc() and exit again so you can deal with HTML 'zzz'. But that leaves you outside php mode, right? If the next thing after eval() is more php code, don't you have to enter php mode again like this: eval("?>$string<?php "); echo "hello"; I tried it with and without "<?php" appended to $string. The "hello" always works. Why? Does eval() automatically put you back into php mode? Stated another way, you said that this $string='xxx <?php somefunc("yyy",3); ?> zzz'; eval("?>$string); echo "hello"; is equivalent to: ?>xxx <?php somefunc("yyy",3); ?> zzz echo "hello"; So why doesn't it treat echo "hello" as HTML code in pass-through mode? In fact, it just prints "hello". -- 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

« previous php.general (#73151) next »