What are the best practices for executing shell commands in PHP?

When executing shell commands in PHP, it is important to ensure that the commands are properly sanitized to prevent security vulnerabilities such as command injection attacks. One common approach is to use the `escapeshellcmd()` function to escape any special characters in the command string. Additionally, it is recommended to use functions like `exec()`, `shell_exec()`, or `proc_open()` to execute the commands and capture the output.

$command = 'ls -la';
$escaped_command = escapeshellcmd($command);
$output = shell_exec($escaped_command);
echo $output;