1

How do I execute a linux command in PHP and echo the output in original format?

$out = shell_exec('df');
echo $out;

It seems that this simple method will only print the output in a long string format rather than with the correct number of spaces, tabs, line separators. Any assistance is appreciated. Thanks!

0

1 Answer 1

4

For a browser:

echo "<pre>$out</pre>";

Browsers render HTML. Whitespace has no meaning in HTML, only to format the source. pre tags instruct the browser to render the text as pre-formatted text.

Sign up to request clarification or add additional context in comments.

1 Comment

that works! I'd like echo out [crontab -l] as well, however, I don't believe the webpage has permission to execute that command. Any suggestions? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.