Re: [PHP] Re: Eval var from query

This is a discussion on Re: [PHP] Re: Eval var from query within the PHP General forums, part of the PHP Programming Forums category; The string you send to eval() must be valid PHP code. So try this.. eval( 'echo "'.$data.'";'); - Kevin ----- ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-14-2003
Kevin Stone
 
Posts: n/a
Default Re: [PHP] Re: Eval var from query

The string you send to eval() must be valid PHP code. So try this..

eval( 'echo "'.$data.'";');

- Kevin


----- Original Message -----
From: "Shawn McKenzie" <nospam@mckenzies.net>
To: <php-general@lists.php.net>
Sent: Monday, July 14, 2003 1:15 PM
Subject: [php] Re: Eval var from query


> eval($data)
>
> returns Parse error: parse error, unexpected T_STRING in
> C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1
>
> Thanks!
> Shawn
>
> "Shawn McKenzie" <nospam@mckenzies.net> wrote in message
> news:20030714190325.34064.qmail@pb1.pair.com...
> > How can I evaluate a var that is from a text field of a database?

> Example:
> >
> > MySQL field `name` = hi my name is $name
> >
> > In my script I have:
> >
> > $name = "Shawn";
> >
> > After fetching a query result as an associative array I have the

contents
> of
> > the `name` field in $data
> >
> > If I echo $data I get: hi my name is $name
> >
> > I would like to get: hi my name is Shawn
> >
> > TIA,
> > Shawn
> >
> >

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



Reply With Quote
  #2 (permalink)  
Old 07-14-2003
Kevin Stone
 
Posts: n/a
Default Re: [PHP] Re: Eval var from query

I realized that may not make any sense. Following up the eample relates to
your original query like this..

> MySQL field `name` = hi my name is $name
> In my script I have:
> $name = "Shawn";


$data = 'hi my name is $name';
$code = 'echo "'.$data.'";';
$name = 'Shawn';
eval($code); // prints "hi may name is Shawn".

Hope that makes it more clear.

- Kevin



----- Original Message -----
From: "Kevin Stone" <kevin@helpelf.com>
To: "PHP-GENERAL" <php-general@lists.php.net>
Sent: Monday, July 14, 2003 1:23 PM
Subject: Re: [php] Re: Eval var from query


> The string you send to eval() must be valid PHP code. So try this..
>
> eval( 'echo "'.$data.'";');
>
> - Kevin
>
>
> ----- Original Message -----
> From: "Shawn McKenzie" <nospam@mckenzies.net>
> To: <php-general@lists.php.net>
> Sent: Monday, July 14, 2003 1:15 PM
> Subject: [php] Re: Eval var from query
>
>
> > eval($data)
> >
> > returns Parse error: parse error, unexpected T_STRING in
> > C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1
> >
> > Thanks!
> > Shawn
> >
> > "Shawn McKenzie" <nospam@mckenzies.net> wrote in message
> > news:20030714190325.34064.qmail@pb1.pair.com...
> > > How can I evaluate a var that is from a text field of a database?

> > Example:
> > >
> > > MySQL field `name` = hi my name is $name
> > >
> > > In my script I have:
> > >
> > > $name = "Shawn";
> > >
> > > After fetching a query result as an associative array I have the

> contents
> > of
> > > the `name` field in $data
> > >
> > > If I echo $data I get: hi my name is $name
> > >
> > > I would like to get: hi my name is Shawn
> > >
> > > TIA,
> > > Shawn
> > >
> > >

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

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



Reply With Quote
  #3 (permalink)  
Old 07-14-2003
Shawn McKenzie
 
Posts: n/a
Default Re: [PHP] Re: Eval var from query

Got it!

eval( '$newdata = "'.$data.'";');

Thanks!
Shawn

"Shawn McKenzie" <nospam@mckenzies.net> wrote in message
news:20030714195112.90181.qmail@pb1.pair.com...
> Thanks Kevin! That works great. It outputs: hi my name is Shawn
>
> Now if I want to assign $data to another var, let's say $newdata and have

it
> eval the $name var inside of that. How would that work?
>
> Meaning I want to $newdata = hi my name is Shawn
>
> Thanks!
> Shawn
>
> "Kevin Stone" <kevin@helpelf.com> wrote in message
> news:009801c34a3d$65aad1e0$6500a8c0@kevin...
> > The string you send to eval() must be valid PHP code. So try this..
> >
> > eval( 'echo "'.$data.'";');
> >
> > - Kevin
> >
> >
> > ----- Original Message -----
> > From: "Shawn McKenzie" <nospam@mckenzies.net>
> > To: <php-general@lists.php.net>
> > Sent: Monday, July 14, 2003 1:15 PM
> > Subject: [php] Re: Eval var from query
> >
> >
> > > eval($data)
> > >
> > > returns Parse error: parse error, unexpected T_STRING in
> > > C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1
> > >
> > > Thanks!
> > > Shawn
> > >
> > > "Shawn McKenzie" <nospam@mckenzies.net> wrote in message
> > > news:20030714190325.34064.qmail@pb1.pair.com...
> > > > How can I evaluate a var that is from a text field of a database?
> > > Example:
> > > >
> > > > MySQL field `name` = hi my name is $name
> > > >
> > > > In my script I have:
> > > >
> > > > $name = "Shawn";
> > > >
> > > > After fetching a query result as an associative array I have the

> > contents
> > > of
> > > > the `name` field in $data
> > > >
> > > > If I echo $data I get: hi my name is $name
> > > >
> > > > I would like to get: hi my name is Shawn
> > > >
> > > > TIA,
> > > > Shawn
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >

> >
> >

>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:22 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0