2012-05-23 68 views
-1

如何EREG以下語句轉換到的preg_replace如何將ereg_replace轉換爲php中的preg_replace?

$message = ereg_replace("http://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $message); 
$message = ereg_replace("(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $message); 
+0

@adrien:Obiously有人試圖問一個問題;) – hakre

回答

0
$message = preg_replace('~http://([.]?[a-zA-Z0-9_/-])*~', '<a href="$0" target="_blank">$0</a>', $message); 
$message = preg_replace('~(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)~', '$1<a href="http://$2" target="_blank">$2</a>', $message);