Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何替换一段PHP代码_Php_Str Replace - Fatal编程技术网

如何替换一段PHP代码

如何替换一段PHP代码,php,str-replace,Php,Str Replace,我试图用另一段代码替换一段代码。我可以使用较小的字符串,但一旦我将较大的字符串添加到$embedCode,它会在$U COOKIE附近的memberPassword周围抛出一个意外的T_ENCAPSED_和_空格错误 不管怎么说,似乎您正在寻找不解释内部变量的语言构造-因此,您必须使用非herdoc语法-但常规字符串定义受限于' $embedCode = <<<EOF getApplicationContent('video','player',array('id' =>

我试图用另一段代码替换一段代码。我可以使用较小的字符串,但一旦我将较大的字符串添加到$embedCode,它会在$U COOKIE附近的memberPassword周围抛出一个意外的T_ENCAPSED_和_空格错误

不管怎么说,似乎您正在寻找不解释内部变量的语言构造-因此,您必须使用非herdoc语法-但常规字符串定义受限于'

$embedCode = <<<EOF
getApplicationContent('video','player',array('id' => $iFileId, 'user' => $this->iViewer, 'password' => clear_xss($_COOKIE['memberPassword'])),true)
EOF;
$name = str_replace($embedCode,"test",$content);
或者,如Marcx在下面建议的那样,用\来转义$

您应该使用\$


如果您的目标是使用vars名称,如果您想使用变量的实际值,那么问题出在$this->iViewer…

实际上问题出在$u COOKIE上,而不是像您所说的$this->iViewer上
$sample = 'qwe $asd zxc';
$embedCode = <<<EOF
    getApplicationContent('video','player',array('id' => \$iFileId, 'user' => \$this->iViewer, 'password' => clear_xss(\$_COOKIE['memberPassword'])),true)
EOF;