Re: Variables and Strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Moseby wrote:
Thanks for the responses guys, but what i'm saying is i would

...


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.

exactly - nicely put Jim.


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.

hopefully thats clear to the OP now - and he can [re]state his goal in
order that we might point him into a more fruitful direction!


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.

yeah 'Superman' explain what it is you want to do AND why - then maybe we can
give you some help - what you are currently asking is impossible (well actually
Jay Blanchard hinted at a way to do it but I firmly believe that its conceptually
over your head atm and very probably not a good solution to what you want to acheive -
which is not to say that Jays hint was crap or wrong; more like the problem you
posed originally is moot.)


JM

Because it ruins the flow of the conversation.

evil genius ;-)


Why is top posting a bad thing?



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux