3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; }
based on RMEpt
Output for 4.3.10 - 4.4.9, 5.0.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
ê[B]éî<I>øo</I>oë[/B]å [U]aí[/U] ê[B]éî<I>øo</I>oë[/B]å [U]aí[/U]
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/o6VNW on line 16 ê[B]éî<I>øo</I>oë[/B]å [U]aí[/U]PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/o6VNW on line 21 ê[B]éî<I>øo</I>oë[/B]å [U]aí[/U]PHP_EOL