如何 str_replace 一段 PHP 代码 [英] How to str_replace a section of PHP Code

查看:30
本文介绍了如何 str_replace 一段 PHP 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在尝试用另一段代码替换一段代码.我可以用较小的字符串来做,但是一旦我将较大的字符串添加到 $embedCode 中,它就会抛出意外的 T_ENCAPSED_AND_WHITESPACE"错误

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

推荐答案

你应该使用 \$

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

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

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...

这篇关于如何 str_replace 一段 PHP 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆