在PHP中执行多行sed:转义问题 [英] Executing multiline sed in php: escaping issues
本文介绍了在PHP中执行多行sed:转义问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行sed进行多行搜索,并替换为以下字符串
I am trying to run sed to do a multiline search and replace with the following string
$test = "sed -n '1h;1!H;${;g;s/iname=\"".$name.".*item>/".trim(xml)."/g;p;}' ".$file;
exec($test,$cmdresult);
选择
sed是因为要搜索的字符串超过10 mb.
sed is choice since the string to be searched is over 10 mb.
在执行过程中,编译器发出警告
During execution compiler issues a warning
PHP Parse error: syntax error, unexpected ';'
我该如何解决这个问题?
How do I go about solving this?
推荐答案
您需要对${}
中的$
进行转义.
You need to escape the $
in ${}
.
$test = "sed -n '1h;1!H;\${;g;s/iname=\"".$name.".*item>/".trim(xml)."/g;p;}' ".$file;
exec($test,$cmdresult);
但是,为了让人们阅读您的代码,您应该真正地将字符串分割开.通过串联其他字符串sprintf
或HEREDOC来创建它.
In order to let humans read your code, though, you should really split the string up. Create it by concatenating other strings, sprintf
or HEREDOC.
这篇关于在PHP中执行多行sed:转义问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文