Re: parse_string() or similar functionality?
| From: | Jade Nicoletti | Date: | Tue, 06 Jun 2000 15:12:40 +0000 |
| Subject: | Re: parse_string() or similar functionality? | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-20333@lists.php.net to get a copy of this message | ||
function parse_string($string) {
ob_start();
eval("?>$string<?");
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
On Tue, Jun 06, 2000 at 11:00:58AM -0400, Colin Viebrock wrote:
> 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!
>
> Basically, can you run the PHP parser on a string that contains
> PHP code? This would sort of be like include(), except that
> it takes a string instead of a file, and it stores the output in
> a string, instead of echo-ing it.
>
> All attempts with eval() and preg_replace('/.../e') have proved
> futile. :)
>
> __________________________________________________________________
> Colin Viebrock easyDNS Technologies
> Co-Founder control your domain
>
> http://www.easyDNS.com
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
===============================================================================
Jade Nicoletti Nicoletti Net Services Tel. 01 240 4774
Geschäftsleitung Postfach 2519 Fax 01 240 4775
System-Administration 8021 Zürich
============================================[ Weitere Infos: http://nns.ch/ ]==