How can variables containing PHP/SQL code be stored and outputted correctly to avoid issues with variable definitions?

When storing variables containing PHP/SQL code, it's important to properly escape the content to avoid conflicts with variable definitions. One way to do this is by using the `htmlspecialchars()` function to encode special characters in the code. This ensures that the code is stored safely and can be outputted correctly without causing any issues with variable definitions.

// Example of storing and outputting a variable containing PHP/SQL code
$code = "<?php echo 'Hello, world!'; ?>";
$escaped_code = htmlspecialchars($code);

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