<?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[2]); }, $string); echo $result;
You have javascript disabled. You will not be able to edit any code.