My Code is:
$data = shell_exec('ls -l /var/www/html | awk '{print $5,"|",$9}'');
echo "<pre>$data</pre>";
Why doesn't this work?
The problem is that you have single quotes inside other single quotes.
When you run it, PHP will show the following error:
PHP Parse error: syntax error, unexpected '{' in file.php on line 3
It halts on the {
since it comes after the closing (2nd) single quote and obviously doesn't belong there.
To include quotes inside other identical quotes, you can prefix them with a backslash (\
) such that your code would be:
$data = shell_exec('ls -l /var/www/html | awk \'{print $5,"|",$9}\'');
echo "<pre>$data</pre>";