【发布时间】:2011-08-29 06:02:34
【问题描述】:
我有这个代码正则表达式,它应该将各种不同的 url 转换为某些文本中的链接。
preg_replace 代码是:
$regex = '@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@';
$text = preg_replace($regex, '<a href="$1">$1</a>', $item);
现在它几乎适用于您可以想象的所有 URL,但我遇到的问题是逗号和 URL 中的特殊字符...
问题让我感到:
http://www.sdfsdfsdf.sd/si/391,1000,1/more.html
http://sdfsddsdf-sdfsdfds.sr/component/option,com_contact/Itemid,3/lang,si/
在stackoverflow上很有趣,这两个都可以:)
谢谢,最好的问候,
【问题讨论】:
标签: php url text preg-replace hyperlink