----- Original Message -----
From: "John A. Grant" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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, [EMAIL PROTECTED]
----------------------------------
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
----------------------------------


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to