3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'ê[B]éî[I]øo[/I]oë[/B]å [U]aí[/U]'; $isMatch = preg_match( '~\[(\w++)([=]?)([^\]]*?)\]([^\[]*?)\[/\1\]~', $string, $matches ); if($isMatch) { echo str_replace( "[{$matches[1]}]{$matches[4]}[/{$matches[1]}]", "<{$matches[1]}>{$matches[4]}</{$matches[1]}>", $string ) . PHP_EOL; echo str_replace( $matches[0], "<{$matches[1]}>{$matches[4]}</{$matches[1]}>", $string ) . PHP_EOL; }

preferences:
29.8 ms | 402 KiB | 5 Q