Are there any best practices for handling multiple occurrences of [php] tags in a string when formatting in PHP?

When handling multiple occurrences of [php] tags in a string in PHP, one approach is to use the `preg_replace_callback()` function to replace each occurrence with the evaluated result of the PHP code within the tags. This allows for dynamic execution of PHP code within the string.

<?php
$string = "Hello [php]echo 'world';[/php]!";
$pattern = '/\[php\](.*?)\[\/php\]/';
$result = preg_replace_callback($pattern, function($matches) {
    ob_start();
    eval($matches[1]);
    $output = ob_get_clean();
    return $output;
}, $string);

echo $result; // Output: Hello world!
?>