Re: Parsing variables within string variables

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

 



Dear Paul,

this is exactly the problem: the string including the dollar sign comes 
from the database.

The problem I have is that the echo statement parses the $bar reference, 
but not the $foo reference within it.

So

   echo $bar

generates

   Hello $foo

which is better than 

   $bar

but doesn't get as far as

   Hello cat

What I think I need is to send the results of the first echo to a second 
echo for parsing. Is there some way of doing that?

Thanks for any help...

   David.

In article <6.2.3.4.2.20060407102231.0304d230@xxxxxxxxxxxxxx>,
 paul@xxxxxxxxxxxxxxxxxxx (Paul Novitski) wrote:

> I wrote:
> >You need to EVALUATE the string coming from the database:
> >
> >Assuming that $sDataField contains the string 'Hello $foo':
> >
> >         $foo = "cat";
> >         $sText = eval($sDataField);
> >
> >RESULT: $sText = "Hello cat"
> >
> >http://php.net/eval
> 
> 
> I was assuming that you meant that the string "Hello $foo" -- 
> including the dollar sign -- came from the database.
> 
> If $foo exists as a native PHP variable, I'd want to see your actual 
> code to tell why it's not being properly evaluated by the parser.
> 
> Sometimes you need to use curly braces to help the PHP interpreter 
> differentiate a variable from the surrounding text:
> 
>          $bar = "Hello ${foo}amaran";
> 
> If you escape the dollar sign, the variable won't be evaluated:
> 
>          $bar = "Hello \$foo";
>          RESULT: "Hello $foo"
> 
> Paul

-- 
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