Re: finding variables and expanding them
| From: | Matthew Leingang | Date: | Fri, 27 Oct 2000 14:22:08 +0000 |
| Subject: | Re: finding variables and expanding them | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22335@lists.php.net to get a copy of this message | ||
Hello Darcy,
Check out:
http://www.php.net/manual/function.preg-replace.php
especially the part about the /e modifier. You might need something like
(untested)
$buffer = preg_replace("/^\$[^[:space:]]*/e","\$\\1",$buffer);
HTH,
Matt
----------------------------------------------------------------
Matthew Leingang http://www.math.rutgers.edu/
Rutgers University leingang@math.rutgers.edu
Department of Mathematics "This signature needs no quote."
On Thu, 26 Oct 2000, darcy w. christ wrote:
> i have a case where i am reading a file which might have variables in it
> (eg. $name). i don't necessarily know the name of the variables, i just
> know that if there is one which begins with a $, i want to be able to
> expand it. Now, is there a way to expand this and still keep the
> contents of that file in a variable. i've been playing around with
> ereg_replace, but i can't seem to use an eval or ${}.
>
> $buffer =
> ereg_replace("\\$[^[:space:]]*","eval('\\1')",$buffer);
> $buffer = ereg_replace("\\$[^[:space:]]*","${'\\1'}",$buffer);
>
> does anyone know of a way to do this? i appreciate the help.
>
> --
> ~darcy w. christ
> Elegant Communications Inc.
> 416.362.9772 x222 | 416.362.8324 fax
>
> --odlilbdfjnmkfhjflhcc
> Content-Type: message/rfc822
> Content-Disposition: inline; filename="php-general_22200.ezm"
>