开发者

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

开发者 https://www.devze.com 2023-01-01 11:37 出处:网络
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

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

精彩评论

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

关注公众号