What are the best practices for handling command execution in PHP to avoid unexpected output like "Content-type: text/html"?

When executing shell commands in PHP using functions like `exec` or `shell_exec`, it's important to capture the output properly to avoid unexpected content like "Content-type: text/html". To do this, you should use output buffering and capture the command output in a variable. This will prevent any headers or other content from being displayed before the actual command output.

<?php
// Execute command and capture output
ob_start();
exec('your_command_here', $output);
ob_end_clean();

// Process the output as needed
foreach ($output as $line) {
    echo $line . "<br>";
}
?>