Would anyone be able to advise on why the shell_exec code is returning an error? If more information is needed, please let me know. Thanks in advance.

Error Message
Parse error: syntax error, unexpected '.' on line 3

Complete Code (and the only line of code in the script)

$cleana = shell_exec ("find . -iname '*.txt' -exec replace "\\" "" -- {} \;");

For note, when executing "find . -iname '*.txt' -exec replace "\" "" -- {} \;" through ssh it works correctly (not sure if this is relevant)

Php Version 5.2.17

    Welcome to PHPBuilder! When posting PHP code, please use the board's [noparse]

    ..

    [/noparse] bbcode tags as they make your code much easier to read and analyze.

    oconus;10996329 wrote:

    Would anyone be able to advise on why the shell_exec code is returning an error?

    It isn't. PHP never got the chance to even try to execute the command because it couldn't even parse your PHP script.

    After adding the bbcode tags, the reason for this becomes apparent; you've got unescaped double quotes inside of a double quote delimited string.

    EDIT: Okay, vBulletin is quite broken and likes to mangle backslashes at times, so I switched back to [noparse]

    ..

    [/noparse]. :/

      bradgrafelman;10996335 wrote:

      It isn't. PHP never got the chance to even try to execute the command because it couldn't even parse your PHP script.

      After adding the bbcode tags, the reason for this becomes apparent; you've got unescaped double quotes inside of a double quote delimited string.

      Thank you.

      I altered the code to below and currently and am not receiving any errors however it does not process the txt files. Would you be able to further assist?

      $cleana = shell_exec ("find . -iname '*.txt' -exec replace \"\\" \"\" -- {} \;");

      Just another note. I am looking to remove any backslashes from txt files on the server (again not sure if this is relevant). Thanks.

        Rather than passing that string to shell_exec(), try [man]echo[/man]'ing it out instead - I think you'll find that it isn't the same string you claim works via SSH.

          bradgrafelman;10996340 wrote:

          Rather than passing that string to shell_exec(), try [man]echo[/man]'ing it out instead - I think you'll find that it isn't the same string you claim works via SSH.

          Thank you very much and this has been resolved. The correct code which works is below.

          $cleana = shell_exec ("find . -iname '*.txt' -exec replace \"\\\" \"\" -- {} \;");

            Write a Reply...