-1

when i try parsing a file by executing this command from within php using shell_exec():

$shellCommand = "cat $filelocn | awk 'BEGIN{RS="<br>"}{$1=$1}1' |sed '/CURRENT/d' ";
echo $shellCommand ;

An error is displayed:

PHP Parse error:  syntax error, unexpected '>' in filename.php

i also tried adding \ before ' ie: "cat $filelocn | awk \'BEGIN{RS=\"<br>\"}{$1=$1}1'"; but it again throws error.

How do i resolve this issue ?

Abhishek J
  • 101
  • 7
  • 3
    Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Dekel Oct 23 '16 at 11:50
  • Thank you @Dekel , i looked into it ; but how do i resolve regex parse error – Abhishek J Oct 23 '16 at 11:56
  • It's not regex parse error. it's simply php parse errors. – Dekel Oct 23 '16 at 11:59
  • Case your code would be `echo " abc " def ";` you get the exact same error. – Dekel Oct 23 '16 at 12:00

1 Answers1

0

Unless you're trying to interpolate variables in your PHP code into your string, you need to escape the dollar signs too:

$shellCommand = "cat \$filelocn | awk 'BEGIN{RS=\"<br>\"}{\$1=\$1}1' |sed '/CURRENT/d' ";
echo $shellCommand;

Specifically, the $1s are causing your parse error. If $filelocn is a PHP variable, you don't need to escape it.

Sebastian Lenartowicz
  • 4,695
  • 4
  • 28
  • 39