开发者

php preg_replace, replace anchor href that doesn't contain this keyword

href\=\"(.*)\"

this match all links, what i need is to make it apply on all links except when href has localhost as a key开发者_C百科word on it

Thanks.


I think this regular expression does what you want:

href="(.*)localhost(.*)"


preg_replace("@href\\=\\\"((?:\\b[^l\\\"]|l[^o]|lo[^c]|loc[^a]|loca[^l]|local[^h]|localh[^o]|localho[^s]|localhos[^t]\\b)|[\\w&&[^\\\"]]+localhost|localhost[\\w&&[^\\\"]]+|[\\w&&[^\\\"]]+localhost[\\w&&[^\\\"]]+|[^l\\\"])+\\\"@", $replacement, $str)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜