You are here: RE: [PHP] Variables and Strings « PHP « IT news, forums, messages
RE: [PHP] Variables and Strings

Posted by Jim Moseby on 12/30/05 00:04

>
> 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";
> $Vars=myspecialfunction($Varname);
> echo ($Vars);
>
> that code would produce $Varname, if there were more
> variables it would also
> return the Variable Names in an array

I believe what Jochem is trying to tell you is that when you assign the
string variable, the variable names are expanded to their values, so the
names are no longer available.

Consider this:

$partname='widget';
$amount=100;

$string="This $partname costs $amount dollars";

/*
$string now equals "This widget costs 100 dollars", so when you pass it to
your function, it has no way to know for sure what the variables were, or
that there even were ANY variables involved in the generation of the string.

The variable NAMES are not passed because PHP expands them to their values
and sets $string accordingly.
*/

$string='This $partname costs $amount dollars';

$string now equals "This $partname costs $amount dollars". In this case, I
used single quotes. The values are not expanded and the variable NAMES are
passed. The VALUE of the variables are not. So you could then have a
function look for any word that starts with a $ and return an array of
names.

That all being said, what in the world are you trying to do with this? I
bet you $1.78 (the change in my desk drawer) there is a much better way to
solve whatever problem it is than the way you are trying here.

JM

Because it ruins the flow of the conversation.
>Why is top posting a bad thing?

 

Navigation:

[Reply to this 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

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