3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = <<<STR Hello @username you need to check this http://github.com and @username you need to https://stackoverflow.com/questions/ask or https://stackoverflow.com STR; $pattern = "~(?<!\S)(?:(@[^\s@]+)(?!\S)[^h]*(?:h(?!ttp)[^h]*)*+)?\K((?:https?|ftp|file)://\S+)~"; $result = preg_replace_callback($pattern, function($m){ return sprintf('<a href="%s">%s</a>', $m[2],$m[1] !== "" ? $m[1] : $m[2]); }, $string); echo $result;

preferences:
94.26 ms | 1584 KiB | 5 Q