Bluehost.com Web Hosting $6.95

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; ----- Original Message ----- From: "Shawn McKenzie" <nospam@mckenzies.net> To: <php-general@lists.php.net> ...


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

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


> 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


Umm.. well.. '$name' is a litteral inside the string until it is evaluated.
It doesn't matter if you make a copy of the variable, '$name' is still going
to be a litteral value. So you'll have to eval() it exactly the same way
every time. But maybe I can offer an alternative...

You look at this string and see a "code evaluation" problem. I look at this
string and see a "find and replace" problem. Consider useing str_replace()
to search for and replace '$name' as a template marker rather than a
variable to be evaluated..

$data = 'hi my name is $name';
$name = 'Shawn';
echo str_replace('$name', $name, $data);

This accomplishes exactly the same thing and it's a perfectly valid form.
Plus it's going to work on any string becuase you don't have to turn them
into PHP code first.

- Kevin


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 07:22 AM.


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