Are there specific guidelines for using echo statements in PHP when dealing with non-PHP code?

When dealing with non-PHP code within an `echo` statement in PHP, it's important to properly escape any special characters to prevent syntax errors or unexpected behavior. One common approach is to use the `htmlspecialchars()` function to encode any HTML entities in the non-PHP code before echoing it out.

<?php
// Non-PHP code containing special characters
$nonPhpCode = '<script>alert("Hello World!");</script>';

// Echoing out the non-PHP code with htmlspecialchars
echo htmlspecialchars($nonPhpCode);
?>