【发布时间】:2012-02-25 15:06:55
【问题描述】:
我正在寻找可以改变我的字符串的漂亮正则表达式:
text text website.tld text text anotherwebsite.tld/longeraddress text http://maybeanotheradress.tld/file.ext
进入 bbcodes
text text [url=website.tld]LINK[/url] text text [url=anotherwebsite.tld/longeradress]LINK[/url] text text [url=http://maybeanotheradress.tld/file/ext]LINK[/url]
你能指点一下吗?
【问题讨论】:
-
你将如何区分文本和网站地址?
-
首先我想通过分隔符分割字符串:“:”、“-”和空格键
-
@AdrianK。 “hi.com whit me”(写得不好的短语的例子)。鉴于您当前的规则,
hi.com应被解释为 URL。我建议强制 URL 以协议为前缀。 -
@ArianK:这个问题已经被问过无数次了,即使在今天也是如此。请使用搜索,有不同的方法可以做到这一点,最终它不取决于您是插入 BBCODE 还是仅插入 HTML A 标签。
标签: php regex url replace bbcode