Passing strings that contain variables to be parsed later

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VetteVert
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2004 9:31 am

Passing strings that contain variables to be parsed later

Post by VetteVert »

I have a configuration file with the equivalent of the following:

sql_statement = "select * from $table a where a.x = '$x'"

I then read the sql_statement line from the configuration file in another php file where I would like $table and $x to be parsed. If I leave it like above, it tries to parse it immediately, not later when I need it. Does anyone have any idea on how the sql_statement line could be written so that it would be parsed in the file that reads it?

Thanks!!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

how do you read it? [php_man]file_get_contents[/php_man]
how do you to [php_man]eval[/php_man] the code in the text?
VetteVert
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2004 9:31 am

Post by VetteVert »

The sql_statement string is in config.php, and is included in another php file.

I get to it by going through the array it is in and assign it to $sql:

$x = 'BOB';
$sql = $array["here"]["there"]["sql_statement"];

at this point the variable has already been processed and is blank ('') and not BOB.
VetteVert
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2004 9:31 am

Post by VetteVert »

anybody?
VetteVert
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2004 9:31 am

Post by VetteVert »

guess not :?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

timvw gave you 2 solutions.
VetteVert
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2004 9:31 am

Post by VetteVert »

I caught the first one that didn't apply to me, but somehow completely missed the second...which is exactly what I was asking for. I apologize for the oversight.

Thanks!

VV
Post Reply