sed works properly in SSH, not in PHP

Posted by David on Server Fault See other posts from Server Fault or by David
Published on 2010-12-28T19:29:20Z Indexed on 2010/12/28 19:55 UTC
Read the original article Hit count: 357

Filed under:
|
|

So, I have the following line that I run in PHP with exec($addPHPtags);

$addPHPtags = "/bin/sed -i '/<BODY BGCOLOR=\"#FFFFFF\">/ a\ <?php \n ?> '" . $instance['file'] . " 2>&1";

I'd expect that command to find the key and append it with a php tag. However, when I run it in PHP, I get the following error if I trap command output:

[0] => /bin/sed: -e expression #1, char 39: unknown command: `?'

However, if I run the same command in SSH, it works completely fine:

/bin/sed -i '/<BODY BGCOLOR=\"#FFFFFF\">/ a\ <?php \n ?>' file.php

I'm out of ideas, I've tried various alternatives but to no avail. Any help ? Thanks.

© Server Fault or respective owner

Related posts about php

Related posts about ssh