1

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,

3
  • 1
    In what way isn't it working? Commented Dec 21, 2011 at 1:00
  • Probably the \x, as it should most likely be x instead. Either that or the src=" part... Commented Dec 21, 2011 at 1:05
  • 1
    (Also enable error_reporting whenever something isn't working.) Commented Dec 21, 2011 at 1:08

2 Answers 2

4

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:

 preg_quote('src="http://domain.com/image-', '/')

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Mario, this simple but straight answer solve my problem! ;)
0

try

preg_match_all('/src="http:\/\/domain\.com\/image\-\d{3}xd{3}\.(gif|png|jpg)/'
                inputHTML, $imgs);

I haven't tried this yet, I hope it works :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.