PHP 将 URL 转换为字符串中的链接


PHP convert URL to link in string

$string1 = "You can view the full calendar at 
           http://www.something.org/calendar/57682117 
           or email: info@something.org"
$string2 = "You can view the full calendar at 
           www.something.org/calendar/57682117 
           or email: info@something.org"

这是我拥有的字符串。我需要做的是将两个URL转换为将链接到页面的链接,然后将电子邮件转换为mailto:链接。

我不需要考虑 blahblah.com 的网站。他们将永远拥有这些 www 之一。或 http(s)。我对正则表达式很糟糕...所以帮助将不胜感激!

$output = preg_replace('_<a href="(?!mailto:)(?!tel:)[^"]+[^>]*>(.+?)</a>_', '$1', $string1);
echo '<pre>'.print_r(htmlentities($output), true).'</pre>';