开发者

url matching regex for php

I'm looking for a pattern that can match urls.

All of them will contain ".no" as there is only Norwegian domains input.

I think whats needed is this:

search for a space or linebreak before and after '.no', and the match will be a link.

Some examples of what it should match (all with text around it):

test.no
test.no/blablabla/
test.no/blablabla/test.html
test.no/blablabla/test.php
test.no/blablabla/test.htm

and this should then be replaced with

<a href="http://www.MATCH">MATCH</a>
开发者_开发知识库

anyone can figure this out?


This should do it:

 $html = preg_replace("#\w+\.no[\w/.-]*#", '<a href="http://www.$0">$0</a>', $html);


Check John Gruber's Regular expression for URLs and go on from there.


I hope this is strict enough: ^[\w\d-\.\\]+.no.*$

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜