On Thu, December 29, 2005 3:31 pm, PHP Superman wrote:
> Thanks for the responses guys, but what i'm saying is i would like to
> return
> all the variable names i have in a string,
> $String="Blah Blah Blah $VarName Blah Blah Blah";

$VarName = 'xyz';
$String now has "Blah Blah Blah xyz Blah Blah Blah" in it.

There is *NOTHING* left to indicate that xyz came from a variable.

You simply do not have the context available to do what you want.

Now, you *COULD* do like this:

$VarName = 'xyz';
$Template = 'Blah Blah Blah $VarName Blah Blah Blah';

Note the use of single quotes that does NOT interpret variables.

You now have a $Template from which, with luck, you could:
A) compose $String using:
eval('$String = "$Template";');

B) use something not unlike this:
preg_match_all('/\\$([a-z0-9_]+/sU', $Template, $variables);
foreach($variables[1] as $varname){
  echo "$varname = ", $$varname;
}

I'll warn you right now that whatever it is you are doing, there is
PROBABLY a better easier way to do it, but you've put on blinders to
other solutions and only asked us how to do what you think you want to
do, which is probably not what you really want to do...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to