Here is my code and I am getting an error like this.
Parse error: syntax error, unexpected '' ";' (T_ENCAPSED_AND_WHITESPACE) in C:\\wamp64\\www\\PHPQC\\php\\base\\meditabmssql\\med_page.php(1369) : eval()'d code on line 1.
Code:
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string wi"th my $name in it.';
eval("\$str = \"$str\";");
echo $str;
?>
here is a reference( http://php.net/manual/en/function.eval.php )
You should escape some characters:
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string wi"th my $name in it.';
eval("\$str = \"\$str\";");
echo $str;
?>
You need to escape the quotes that are inside $str
. You can use addslashes()
for this.
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string wi"th my $name in it.';
$strslash = addslashes($str);
eval("\$str = \"$strslash\";");
echo $str;
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.