3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "this is [my] test [string] and [<script>alert(1)</script>] is very long [with] so many pwords]"; echo preg_replace_callback( "#\[([^\]]+)]#", fn($m) => sprintf( '<a href="/story.php?%s">%s</a>', http_build_query(['word' => $m[1]]), htmlspecialchars($m[1]) ), $str );

preferences:
27.35 ms | 407 KiB | 5 Q