duanlu1793 2012-04-22 21:21
浏览 63
已采纳

用于Sed命令的PHP中的Escaped Quotes

I have the following php code

if (!($stream = ssh2_exec($con, 'sed -i \'s/motd=A Minecraft Server/motd=\'.$name.\'s     Server/g\' /home/servers/runner15/server.properties
'))) {

But when I run it instead of replacing the text "motd=A Minecraft Server" to "motd=runner15s Server" it Changes it to motd=..s Server

It's something todo with escaping the quotes

Oh by the way $name holds runner15

  • 写回答

2条回答 默认 最新

  • dongnaoxia0927 2012-04-22 21:24
    关注

    Basic PHP strings... ' strings do NOT interpolate variables, so your sed command contains a literal $, n, a, m, e, etc... That'll be interpreted as a non-existent shell varaible on the remote server, and expand to an empty string.

    [...snip...]otd=A Minecraft Server/motd=\''.$name.'\'s [..snip...]
                                              ^-------^--- 'exit' the string in your client-side PHP
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料