Re: parse_string() or similar functionality?
| From: | Faisal Nasim | Date: | Tue, 06 Jun 2000 15:17:41 +0000 |
| Subject: | Re: parse_string() or similar functionality? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-20335@lists.php.net to get a copy of this message | ||
||How easy would it be to add something like this:
||
|| $string = 'The date is <? echo date("d-M-Y"); ?> today!';
|| echo $string;
|| $new = parse_string($string);
|| echo $new;
||
||The output would be:
||
|| The date is <? echo date("d-M-Y"); ?> today!
|| The date is 06-06-2000 today!
|
|
|I posted this a while back, here it is again:
Clarification: I didn't post this snipped, just
the algorithm.
|<?
|$string = 'The date is <? echo date("d-M-Y"); ?> today!';
|echo $string;
|echo "\n";
|$new = eval ("?>$string");
|echo $new;
|?>
A little info about whats happening:
When you:
<? eval ( "Today is etc" ); ?>
Its same as:
<? Today is etc ?>
Which doesn't make any sense!
So you can use:
<? eval ( "?>Total is etc" ); ?>
Which would be equivalent to:
<??>Today is etc
and will work.
But once out of eval(), php interprets the rest
of the text as part of PHP code without an
explicit <?. So, I think that feature is not a feature
but a hack, which may not work in the future versions.
Enjoy!
Faisal