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条)

报告相同问题?

悬赏问题

  • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥20 wpf datagrid单元闪烁效果失灵