Are there any best practices for handling HTML code when using shell_exec in PHP?

When using shell_exec in PHP to execute commands that involve HTML code, it is important to properly escape the HTML code to prevent any potential security vulnerabilities such as code injection or XSS attacks. One way to do this is by using functions like htmlspecialchars to encode the HTML code before passing it to shell_exec.

$htmlCode = "<h1>Hello, World!</h1>";
$escapedHtmlCode = htmlspecialchars($htmlCode);

$output = shell_exec("your_command_here $escapedHtmlCode");

echo $output;