PHP +正则表达式
我很难尝试从特定文本/文章中删除重复的图像。
假设我有一个图像标签,其中 src="http://domain.com/image.jpg" 和 我想删除(/隐藏)具有以下模式的所有图像:
http://domain.com/image-999x999.jpg
当前,我的正则表达式是(并且它不起作用):(
'/'.preg_quote('src="http://domain.com/image-').'([0-9]{3}\x[0-9]{3})\.(gif|png|jpg)/i'
作为示例,正则表达式应该忽略此: http://domain.com/image-20-999x999.jpg)
欢迎任何建议!
干杯,
I'm having a hard time trying to remove duplicated images from an specific text/article.
Let's say that I have an image tag where the src="http://domain.com/image.jpg" and
I want to remove(/hide) all the images that have the following pattern:
http://domain.com/image-999x999.jpg
Currently, my regex expression is (and it isn't working):
'/'.preg_quote('src="http://domain.com/image-').'([0-9]{3}\x[0-9]{3})\.(gif|png|jpg)/i'
(the regex, as an example, should ignore this: http://domain.com/image-20-999x999.jpg)
Any suggestions are more then welcome!
Cheers,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,
preg_quote()
不起作用,因为您遗漏了第二个范围。它需要知道您使用的分隔符,否则它无法转义:不过,您最好可以为正则表达式本身使用另一个分隔符。就像您的基本 href 中不存在的
#
一样。如果它只是那个固定字符串,那么实际上不需要引用。In this case the
preg_quote()
isn't working, because you left out the second parameter. It needs to know your used delimiter, else it can't escape it:Preferrably you could use another delimiter for the regex itself however. Like
#
that isn't present in your base href. And you don't actually need the quoting if it's just that fixed string.尝试一下
,我还没有尝试过,我希望它有效:)
try
I haven't tried this yet, I hope it works :)