Reply to Re: [PHP] Variables and Strings

Your name:

Reply:


Posted by "Richard Lynch" on 12/30/05 21:39

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация