March 29th, 2010, 10:37 AM
Abnormal IMG SRC?
I've wasted too many hours trying to figure this out
Can I use a single pattern to extract the (correct) src attribute of image tags (even if there are mutiple src attributes)?
E.g. what pattern can get the 2nd src attribute of the 1st tag and the only src attribute of the 2nd tag?
<img onError= src="http://images.play.com/SiteCSS/Play/Live2/2010032301/img/proxy/01m.gif" src="http://images.play.com/covers/10667429m.jpg" alt="Tim Burton's Alice In Wonderland" style="border-width:0px;height:178px;width:117px;" />
<IMG SRC="http://images.play.com/banners/content/Alice 6.jpg " ALT="Alice In Wonderland" />
This is the latest pattern I have tried:
define('IMG_SRC_PATTERN', '#[^onError= ]*src=[\"\']?([^"\']+)#i');
preg_match(IMG_SRC_PATTERN, $tag, $match);
I think I may have stumbled onto the pattern I need, but I'm not sure if it is efficient or not. Can anyone advise?
$pattern = "#(= src=['\"].+[^\"]?)?src=[\"']?([^\"']+)#i";
:: My blip.fm tunes :: Web Design Feeds :: Web Dev Feeds :: CheatSheets :: PHP :: MySQL :: 13 Moon FB App.
"All matter is merely energy condensed to a slow vibration. We are all one consciousness experiencing itself - subjectively. There is no such thing as death, life is only a dream. We are the imaginations of ourselves."
- Bill Hicks
"Truth is hidden in the subtle nature of the heart of everything, although it is invisible. One cannot see it from inside and neither from the surface. One can only live and experience it."
- Heart Sutra
Last edited by b3n : March 29th, 2010 at 10:57 AM.