What are the common challenges faced when parsing [PHP] and [code] tags in a BBCode parser?

When parsing [PHP] and [code] tags in a BBCode parser, a common challenge is properly handling the PHP code within the tags without executing it. To solve this, you can use htmlspecialchars to escape the PHP code and prevent it from being executed.

// Example code snippet to handle [PHP] and [code] tags in a BBCode parser
$bbcode = "[PHP]echo 'Hello, World!';[/PHP]";
$bbcode = str_replace('[PHP]', '<pre><code>', $bbcode);
$bbcode = str_replace('[/PHP]', '</code></pre>', $bbcode);

echo htmlspecialchars($bbcode);