Jump to content

delete all images in a page


anarchoi

Recommended Posts

what syntax can i use with str_replace to delete ALL images tags in a variable?

 

i'd like to take out all <IMG SRC='""> but there is a lot and the url vary, and there are often others tags like WIDTH="" and HEIGHT=""

 

could anyone give me the syntax to use? thanks

Link to comment
Share on other sites

@effigy,

 

Our RegEx's appear to do the exact same thing, but using different logic. After reviewing yours it appears more elegant and easier to understand. However, I'm curious, did you see a flaw in my expression or did you just want to post your version?

Link to comment
Share on other sites

My expression is more efficient in theory. It's best to use greediness when you can expect a certain format; for instance, it's impossible for an open HTML tag to contain another (e.g., <img <h1>x</h1>>) and, knowing this, we can tell the engine to race forward gobbling non ">"s, rather than checking at every step along the way to make sure a ">" is not ahead.

 

As a general rule, when you can, be as specific as possible. Greedy quantifiers and negated characters classes are typically more efficient and internally optimized compared to lazy quantifiers.

 

My apologies for not being as informative up front.

Link to comment
Share on other sites

Thanks for the elaboration. A quick test verified your position. It's not that I don't believe you - I just always test something, if possible, instead of blindly accepting.

 

Running through 10,000 itterations of both methods gave varrying results, but the latter method was approximately 50% faster: 0.1 seconds vs. .05 seconds. Considering that is for 10,000 itterations the difference may not seem relevant. But, for sites with a large amount of traffic every little bit adds up.

 

Thanks again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.