r0nd3L Posted September 9, 2009 Share Posted September 9, 2009 Hi, I haven't done PHP in a while and never got around to learning string matching patterns and what not. What I'm trying to do, is use preg to pull out an img src from HTML website. This proves rather hard as there are a lot of images and I need specific one. What helps is that the image all the time ends in pgallery.jpg, so that's something I need to fish for. Here is a sample IMG src from a website: <img src="image.php?i=2091_paugust/2091_pgallery.jpg" id="i_vv4-35" height="300" width="300"> Is this even possible to do? Thanks! Link to comment https://forums.phpfreaks.com/topic/173721-pulling-image-source-from-html/ Share on other sites More sharing options...
thebadbad Posted September 9, 2009 Share Posted September 9, 2009 Try this: <?php //$str contains the source code preg_match('~<img\b[^>]+src="([^"]*pgallery.jpg)"~i', $str, $match); echo $match[1]; ?> It searches for the first img tag, where the value of the src attribute ends in pgallery.jpg. Link to comment https://forums.phpfreaks.com/topic/173721-pulling-image-source-from-html/#findComment-915723 Share on other sites More sharing options...
r0nd3L Posted September 10, 2009 Author Share Posted September 10, 2009 Thanks, that works brilliantly! I'll have to look into learning those patterns, they're too useful. Link to comment https://forums.phpfreaks.com/topic/173721-pulling-image-source-from-html/#findComment-916275 Share on other sites More sharing options...
thebadbad Posted September 11, 2009 Share Posted September 11, 2009 I can recommend http://www.regular-expressions.info/. Link to comment https://forums.phpfreaks.com/topic/173721-pulling-image-source-from-html/#findComment-916722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.