preg_match help - stripping img tag - help

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need help with a regex.  Been at it for hours and need some sanity
help :>

I am using preg_match in PHP to strip a IMG html tag. I want to strip
any IMG tag that has /work/doc?g= in the SRC attribute.

The basic one i wrote works but obviously doesnt work when you add the
height/width attribute into it:
"<img src=\"\/work\/doc\?g\=([A-Z]+)\">"

some possible variations i am encountering:
<img height="42" src="/work/doc?g=ABCDEFG" width="234">
<img style="WIDTH: 258px; HEIGHT: 46px" src="/work/doc?g=HIJKLMNOP">

All I want is the ABCDEFG or HIJKLMNOP part.

Can someone write the regex that works?  Any help is greatly

Re: preg_match help - stripping img tag - help wrote in news:1113963237.594139.263190

Quoted text here. Click to load it

Try this one:

preg_match("/<img(.*)src=\"\/work\/doc\?g\=(.*?)\"(.*)>/i", $string1,

Not too pretty but it works with $string1 set to both of your example
variations. $matches[0] contains the entire img tag, and $matches[2] will
hold just the ABCDEFG part. $matches[1] and $matches[3] will vary,
depending upon whether or not there were attributes before or after the
src attribute inside the img tag.



Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
< | PHP scripts, webmaster resources

Re: preg_match help - stripping img tag - help

you rock - that worked thx!

Site Timeline