Re: Parsing variables within string variables

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

 



Thanks for all these responses, but unless I'm missing something none of 
them work for what I need. Quotes are irrelevant: with the string "Hello 
$foo" in $bar

   echo "$bar"
   echo $bar

both produce
   
   Hello $foo

and

   echo '$bar'

produces
   
   $bar

I can't use any of the answers like

   'Hello'.$foo

because I have to parse the string 'Hello $foo' as it comes from the 
database: I don't get to construct it.

I did hold out more hope for the eval function, but it seems to me that 
this is for PHP code in a database, not to evaluate variables.

If anyone else can provide the silver bullet, I will be very grateful.

   David.

In article <David.Clough-6046F3.17371407042006@xxxxxxxxxxxxx>,
 David.Clough@xxxxxxxxxxxx (David Clough) wrote:

> I've been bashing my head against the wall on this, and would be glad of 
> help to stop. 
> 
> I have a variable containing a string that contains the names of 
> variables, and want to output the variable with the variables it 
> contains evaluated. E.g. 
> 
>    $foo contains 'cat'
>    $bar contains 'Hello $foo'
> 
> and I want to output $bar as 
> 
>    Hello cat
> 
> The problem is that if I use
> 
>    echo $bar
> 
> I just get
> 
>    Hello $foo
> 
> Note that $bar is loaded from a database query, so I can't control its 
> contents: I just have to parse it.
> 
> Any help appreciated.
> 
> David.

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