2013-10-04 45 views
-4
$string1 = "You can view the full calendar at 
      http://www.something.org/calendar/57682117 
      or email: [email protected]" 
$string2 = "You can view the full calendar at 
      www.something.org/calendar/57682117 
      or email: [email protected]" 

鏈接這是字符串(S)我有。我需要做的是將兩個網址轉換爲鏈接到頁面的鏈接,然後將電子郵件轉換爲mailto:鏈接。PHP轉換的URL字符串

我並不需要考慮網站,是blahblah.com。他們將永遠擁有這些www中的一個。或http(s)。我用正則表達式很糟糕...所以幫助將不勝感激!

+0

這些都沒有解決如何搜索只是一個簡單的網站www或http。此外,「重複」搜索m.site.com和其他...與我正在查找的內容不相關... – user1470118

回答

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

這不起作用。我只是測試它,並沒有產生任何鏈接或任何我提供的例子。 – user1470118