3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = <<<TEXT <pre> ** Bold Text ** // Italic Text // __ Underline Text __ </pre> ** Bold Text ** // Italic Text // __ Underline Text __ __** Bold Text ** Nested Text __ <code> ** Bold Text ** // Italic Text // __ Underline Text __ </code> TEXT; do { $text = preg_replace_callback( '# <(pre|code)>.*?</\1>(*SKIP)(*FAIL) |([*_/])\2(.*?)\2\2 #six', fn($m) => sprintf( '<%1$s>%2$s</%1$s>', strtr($m[2], '*/_', 'biu'), $m[3] ), $text, -1, $count ); } while ($count); var_export($text);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
'<pre> ** Bold Text ** // Italic Text // __ Underline Text __ </pre> <b> Bold Text </b> <i> Italic Text </i> <u> Underline Text </u> <u><b> Bold Text </b> Nested Text </u> <code> ** Bold Text ** // Italic Text // __ Underline Text __ </code>'

preferences:
74.19 ms | 402 KiB | 62 Q