3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = 'This is a demo paragraph with a wrapped string ~here~, with another string ~~here~~.'; echo preg_replace_callback('/~~([\s\S]*?)~~(?!~)|~([^~]*)~/', function ($m) { return !empty($m[1]) ? '<span class="classTwo">' . $m[1] . '</span>' : '<span class="classOne">' . $m[2] . '</span>'; },$html);

preferences:
31.99 ms | 402 KiB | 5 Q