|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-04-25 21:59 UTC] ca50015 at yahoo dot com
Description: ------------ Got parse error when double-quoted string contains variable. [Code] $pattern = "/\<$tagName[^\>]*\>/i"; [/Code] [Error message] Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in php5bug.php on line 6 [/Error message] I'm using php5.0.0rc1 in windows 98 from command line the command is: "php -f php5bug.php" the same I got while test with php5.0.0RC2 Reproduce code: --------------- <?php $text = "<script></script>"; $tagName = 'script'; //These won't work $pattern = "/\<$tagName[^\>]*\>/i"; //backslash not escaped $pattern = "/\\<$tagName[^\\>]*\\>/i"; // backslash escaped //These work $pattern = "/\<" . $tagName . "[^\>]*\>/i"; //backslash not escaped $pattern = "/\\<" . $tagName . "[^\\>]*\\>/i"; // backslash escaped ?> Expected result: ---------------- variables in double-quoted string could be altered Actual result: -------------- Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\home\php5bug.php on line 6 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 21 21:00:01 2025 UTC |
This is indeed expected behavior, use "<{$tagname}[..." instead.