3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('PINGTAGS', [ '#' => 'hashtag.php?hashtag', '@' => 'user.php?user' ]); function convert_text($str) { return preg_replace_callback( "~(?i)\bhttps?[-\w.\~:/?#[\]@!$&'()*+,;=]+|[@#](\w+)|U\+([A-F\d]{5})~", function($m) { // var_export($m); // see for yourself if (!isset($m[1])) { return sprintf('<a href="%s">%s</a>', $m[0], $m[0]); } if (!isset($m[2])) { return sprintf('<a href="%s=%s">%s</a>', PINGTAGS[$m[0][0]], $m[1], $m[0]); } return "<span class=\"emoji\">&#x{$m[2]};</span>"; }, $str); } echo convert_text( <<<STRING This is a @ping and a #hash. This is a www.example.com, this is http://example.com?asdf=1234#anchor https://www.example.net/a/b/c/?g=5&awesome=foobar# U+23232 http://www5.example.com https://sub.sub.www.example.org/ @pong@pug#tagged http://example.com/@dave more http://example.com/more_(than)_one_(parens) andU+98765more http://example.com/blah_(wikipedia)#cite-1 and more http://example.com/blah_(wikipedia)_blah#cite-1 and more http://example.com/(something)?after=parens STRING );
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 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 <a href="user.php?user=ping">@ping</a> and a <a href="hashtag.php?hashtag=hash">#hash</a>. This is a www.example.com, this is <a href="http://example.com?asdf=1234#anchor">http://example.com?asdf=1234#anchor</a> <a href="https://www.example.net/a/b/c/?g=5&awesome=foobar#">https://www.example.net/a/b/c/?g=5&awesome=foobar#</a> <span class="emoji">&#x23232;</span> <a href="http://www5.example.com">http://www5.example.com</a> <a href="https://sub.sub.www.example.org/">https://sub.sub.www.example.org/</a> <a href="user.php?user=pong">@pong</a><a href="user.php?user=pug">@pug</a><a href="hashtag.php?hashtag=tagged">#tagged</a> <a href="http://example.com/@dave">http://example.com/@dave</a> more <a href="http://example.com/more_(than)_one_(parens)">http://example.com/more_(than)_one_(parens)</a> and<span class="emoji">&#x98765;</span>more <a href="http://example.com/blah_(wikipedia)#cite-1">http://example.com/blah_(wikipedia)#cite-1</a> and more <a href="http://example.com/blah_(wikipedia)_blah#cite-1">http://example.com/blah_(wikipedia)_blah#cite-1</a> and more <a href="http://example.com/(something)?after=parens">http://example.com/(something)?after=parens</a>

preferences:
162.66 ms | 411 KiB | 5 Q