0

私は次のPHPコードを持っています

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

しかし、「motd =AMinecraftServer」というテキストを「motd=runner15sServer」に置き換える代わりに実行すると、motd =..sServerに変更されます。

引用符をエスケープすることと関係があります

ちなみに$nameはrunner15を保持しています

4

2 に答える 2

2

基本的なPHP文字列...'文字列は変数を補間しないため、sedコマンドにはリテラル$、、、、、nなどが含まれます...これはa、リモートサーバーに存在しないシェル変数として解釈され、空の変数に展開されますストリング。me

[...snip...]otd=A Minecraft Server/motd=\''.$name.'\'s [..snip...]
                                          ^-------^--- 'exit' the string in your client-side PHP
于 2012-04-22T21:24:40.950 に答える
0

escapeshellcmdssh2_exec の前に試してください。http://www.php.net/manual/en/function.escapeshellcmd.php

于 2012-04-22T21:31:10.470 に答える