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 );
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
this is <a href="/story.php?word=my">my</a> test <a href="/story.php?word=string">string</a> and <a href="/story.php?word=%3Cscript%3Ealert%281%29%3C%2Fscript%3E">&lt;script&gt;alert(1)&lt;/script&gt;</a> is very long <a href="/story.php?word=with">with</a> so many pwords]

preferences:
74.6 ms | 407 KiB | 5 Q