How can the example provided by Corvin be adapted to effectively handle [PHP] tags in a BBCode parser implementation?

The issue with handling [PHP] tags in a BBCode parser implementation is that PHP tags need to be treated differently than regular BBCode tags to prevent them from being executed as PHP code. To solve this, we can modify the BBCode parser to detect and escape PHP tags before processing the rest of the BBCode.

function parseBBCode($text) {
    $text = preg_replace('/\[PHP\](.*?)\[\/PHP\]/s', '[PHP]$1[/PHP]', $text); // Escape PHP tags
    $bbcodes = [
        '/\[b\](.*?)\[\/b\]/s' => '<strong>$1</strong>',
        '/\[i\](.*?)\[\/i\]/s' => '<em>$1</em>',
        '/\[u\](.*?)\[\/u\]/s' => '<u>$1</u>',
        '/\[PHP\](.*?)\[\/PHP\]/s' => '<code>$1</code>', // Render escaped PHP tags as code
    ];
    
    foreach ($bbcodes as $bbcode => $html) {
        $text = preg_replace($bbcode, $html, $text);
    }
    
    return $text;
}

// Example usage
$text = "This is a [b]bold[/b] text with some [PHP]echo 'PHP code';[/PHP] BBCode.";
echo parseBBCode($text);