开发者

How to str_replace a section of PHP Code

$embedCode = <<<EOF
getApplicationContent('video','player',array('id' => $iFileId, 'user' => $this->iViewer, 'password' => clear_xss($_COOKIE['memberPassword'])),true)
EOF;
$name = str_replace($embedCode,"test",$content);

I'm trying to replace a 开发者_开发知识库section of code with another piece of code. I can do it with smaller strings but once I added the larger strings to $embedCode, it throw an "unexpected T_ENCAPSED_AND_WHITESPACE" error


you should unescape the $ using \$

$embedCode = <<<EOF
    getApplicationContent('video','player',array('id' => \$iFileId, 'user' => \$this->iViewer, 'password' => clear_xss(\$_COOKIE['memberPassword'])),true)
EOF;

IF your objective is to use the vars name, if you want to use the real value of the variables, then the problem is in $this->iViewer...


remove ' around the memberPassword near the $_COOKIE

anyway seems you're looking for language construction that not interprets variable inside - so then you have to use not HEREDOC syntax - but regular string definition limited with '

$sample = 'qwe $asd zxc';

or escape $ with \ as Marcx propose below

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜