I have this string:
$str = "<a href=\"http://$domain_var/\">$domain_var</a><br />\n";
And I need to eval it so I use:
eval("\$str = \"$str\";");
Which results in this error:
Parse error: syntax error, unexpected T_STRING in C:\somepath\somefile.php : eval()'d code on line 1
Any ideas what is causing the problem? The culprit seem to be the unescaped quotes in $str but they have to be there.
Thanks!
Tomas
eval problem - unexpected T_STRING in...
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$str = "<a href=\\\"http://\$domain_var/\\\">\$domain_var</a><br />\\n";- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
echoing it doesn't show anything? var_dump($str) to make sure.
-
tomfra
- Forum Contributor
- Posts: 126
- Joined: Wed Jun 23, 2004 12:56 pm
- Location: Prague, Czech Republic
You are right feyd, it does work. My mistake, sorry for that.
Unfortunately, it does not solve my problem completely. I found a difference in eval's behaviour under PHP 4.4.2 & PHP 5+. I just have to make work some code written by someone else which is not easy because there are limits of what I can do with it not to break compatibility.
There is a file called, for example, phpcode.txt. In this file there is some PHP code including this line:
The echo is within a while loop but that should not matter.
Now, in index.php there is this code:
I am not sure why they didn't name phpcode.txt phpcode.php and didn't simply include is but the point is, on my PC which has PHP 5 installed it works perfectly. On another server with PHP 4.4.2 it does not work at all. In the PHP manual there is no mention of any change in the eval function in PHP 5 so I don't get it. It could just as well be a bug in 4.4.2.
Strange.
Tomas
Unfortunately, it does not solve my problem completely. I found a difference in eval's behaviour under PHP 4.4.2 & PHP 5+. I just have to make work some code written by someone else which is not easy because there are limits of what I can do with it not to break compatibility.
There is a file called, for example, phpcode.txt. In this file there is some PHP code including this line:
Code: Select all
echo "<a href=\"http://$domain_var/\">$domain_var</a><br />\n";Now, in index.php there is this code:
Code: Select all
eval(file_get_contents("phpcode.txt"));Strange.
Tomas