string $newUrl. * @return mixed * String, text. */ public static function replaceTextUrls($text, $replace) { $callback = function ($matches) use ($replace) { // ex: $matches[0] == 'http://foo.com' return $replace($matches[0]); }; // Find any HTTP(S) URLs in the text. // return preg_replace_callback('/\b(?:(?:https?):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $callback, $tex return preg_replace_callback('/\b(?:(?:https?):\/\/)[-A-Z0-9+&@#\/%=~_|$?!:,.{}\[\];]*[A-Z0-9+&@#\/%=~_|${}\[\];]/i', $callback, $text); } }