2012-12-05 17 views
0

我有这部分代码为我的txt到URL转换的preg_replace是给错误的URL

$message=preg_replace("/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/", "<a href=\"$1\">$1</a>", $message); 

上面的代码是在我的PHP文件转换$消息(从用户提交一个表单),以在html中的URL。 当用户提供www.google.com时,输出为http://www.MYDOMAIN.com/www.google.com。 我不知道在哪里"<a href=\"$1\">$1</a>"是我的问题。 有什么帮助吗?

回答

0

这样

$message=preg_replace("/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/", "<a href=\"http://$1\">$1</a>", $message); 
+0

一些事情,谢谢!没有工作! – Theodoros80