Hello, world!'; $str = preg_replace_callback( '{(?\w+)(?.*?>)}s', fn($m) => $m['btag'].strtoupper($m['content']).$m['etag'], $str); echo htmlspecialchars($str);