Forum Moderators: coopster
$linkvolume = preg_match_all("'href=\"?(.[^\"\>]*)\"?(.[^\>]*)>(.[^\<]*)</a>'im",$doc[1],$matches);
Right, it's probably is a bit messy, with un-needed bits ;)
But does anyone know how I can deal with images inside hyperlinks? My preg_match quota is running out rapidly for this week ;) i.e. its taking me ages
I tried replacing images with something like "<img.[^\>]*\>" but cant seem to get rid of em.
Anyone with their regex head on that can sort me out would be great!
/added
$match[1] matches the URL, $match[2] anything in between URL and $match[3], the anchor text
I also escaped < and > not sure if thats needed.
<a href = [ac.com...] >Aaron<img src="" /></ a >
or this one
<a href ='http://www.ac.com/'>Aaron<img src="" /></ a >
Your RE will not match those.
But does anyone know how I can deal with images inside hyperlinks?
How do you want to deal with them? Ignore them? Match their URI?
Try this RE:
$pat = <<<END
{href\s*=\s*(["'])?([^'" >]+?)(\\1Ķ )?\s*>([^<]*?)(<img[^>]+>)?</\s*a\s*>}si
END;
$text = <<<END
<a href = [ac.com...] >Aaron<img src="" /></ a >
END;
preg_match_all($pat,$text,$m);
([^<]*?)(<img[^>]+>)? or (.*?) use the latter when you want the entire content of the a elementI believe you are saver when you remove images from the content of the a element in a second step.
preg_replace("'<img[^>]+>'",''$a_content); Sorry for the small font but thatīs the forum software ;)
Andreas
I should have held my breath for an hour or two :)
I have this now
$linkvolume = preg_match_all("'href\s?=\s?\"?\s?(.[^\">]*)\"?(.[^>]*)>(.[^<i]*)<\s*/\s*a\s*>'ims",$doc[1],$matches);
I will jump back offline and study your post
Cheers :)
/added
the images, yes, i wanted to remove them. I may wawnt to get any available title="" for images though I'll try master the normal hyperlinks first.