2012-04-22 133 views
0

我有以下的PHP代碼躲過行情sed命令

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

但是當我運行它,而不是替換文本「MOTD = A的Minecraft服務器」到「MOTD = runner15s服務器」它改變了它到MOTD = ..■服務器

這件事情與待辦事項的方式$名逃逸引號

哦持有runner15

回答

2

基本PHP串... '字符串做不插入變量,所以你的sed命令包含一個文字$,n,a,m,m,e等......這將被解釋爲遠程服務器上不存在的可變shell,並展開爲空字符串。

[...snip...]otd=A Minecraft Server/motd=\''.$name.'\'s [..snip...] 
              ^-------^--- 'exit' the string in your client-side PHP 
+0

我對所使用的詞彙有點困惑,你可以試着向我解釋一下嗎?非常感謝你的幫助! – 2012-04-22 21:27:17

+0

'$ name'不會被'$ name''替代(單引號!) – 2012-04-22 21:33:37

+0

完美!謝謝! – 2012-04-22 21:35:17