NYCPHP Meetup

NYPHP.org

[nycphp-talk] Quick little question - variable interpolation

Adam Fields fields at surgam.net
Thu Oct 17 16:17:40 EDT 2002


On Thu, Oct 17, 2002 at 03:54:58PM -0400, Oktay Altunergil wrote:
> Hm.. "= $one" is not a variable.. I don't know how you would treat it as one. I think you might be able to do something with 'variable variables'.
> 
>  http://www.php.net/manual/en/language.variables.variable.php
> 
> --oktay--

I didn't find anything useful in there.

However, this works. It's not particularly elegant, but it does what I
want:

--------------
$i = 0;
foreach (explode(' ', $test) as $word) {
  if (substr($word, 0, 1) == '$') {
    $newstring[$i] = eval ("return $word;");
  } else {
    $newstring[$i] = $word;
  }
  $i++;
}
print join(' ', $newstring);
--------------

Assuming that $test is my source string.

-- 
				- Adam

-----
Adam Fields, Managing Partner, fields at surgam.net
Surgam, Inc. is a technology consulting firm with strong background in
delivering scalable and robust enterprise web and IT applications.
http://www.adamfields.com



More information about the talk mailing list