<?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);
You have javascript disabled. You will not be able to edit any code.