Great - thanks v. much Mike.  I don't know why there was no mention of
eval() in the section of the manual on Variable Parsing.

James

--
--------------------------------------------------------
www.jholt.co.uk : affordable business website solutions
www.htpshareware.com : software for the disorganized
--------------------------------------------------------

"You don't needs eyes to see, you need vision" - Maxi Jazz

"Mike Ford" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 29 January 2004 14:56, jimbo wrote:
>
> > Hi,
> >
> > I have a query regarding variable parsing.
> >
> > I have some text in a MySQL database in which I have included some
> > variable names.  Eg (but w/o quotes): "thankyou $name for registering
> > on our web site".
> >
> > I query and use mysql_fetch_array to get the data into an associative
> > array. I then build a string and output it like this:
> > echo "blah blah ".$row["thecolumn"]." blah blah";
> >
> > However, the output is simply: "blah blah thankyou $name for
> > registering on our web site blah blah" - i.e. $name does not get
> > parsed.  I have tried wrapping $name with curly brackets in the
> > database but that doesn't help and I have also tried using both
> > addslashes and removeslashes on $row["thecolumn"] and I have also
> > tried this: echo "blah blah $row['thecolumn'] blah blah" - again both
> > with and without curly brackets.
> >
> > Nothing seems to work.  Is what I am trying to do possible?
>
> Yes, but you need to force PHP to re-evaluate the string you retrieve from
> the database -- normally, PHP just uses values retrieved at runtime as-is
> and doesn't do any special interpretation on them.
>
> The function you need to do this is eval() (http://www.php.net/eval), and
> one possible way of using it to achieve your desired result is (off the
top
> of my head, untested):
>
>    eval('echo "blah {$row[\'thecolumn\']} blah";');
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211


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

Reply via email to