rmoss_uk Posted July 9, 2007 Share Posted July 9, 2007 Hi all I need to open a file and loop through it and find all the image file names it contains. The file is a html file so i need to loop through the code and find all occurances of <img> and then extract just the file name in the src attribute for each img in the document. Can anyone show me how to do this using regular extressions or any other way??? Best Regards Richard Moss Quote Link to comment https://forums.phpfreaks.com/topic/59065-difficult/ Share on other sites More sharing options...
NArc0t1c Posted July 9, 2007 Share Posted July 9, 2007 This isn't difficult at all. If you are familiar with the list and explode function, it should be easy. Just use an foreach loop and look trough the contents. Then simply echo out the results. (: Quote Link to comment https://forums.phpfreaks.com/topic/59065-difficult/#findComment-293220 Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 You wanting something like this: http://www.pictureinthesky.net/utils/ripper.php Quote Link to comment https://forums.phpfreaks.com/topic/59065-difficult/#findComment-293224 Share on other sites More sharing options...
sasa Posted July 9, 2007 Share Posted July 9, 2007 try <?php $file = 'poik <img src="sasa.jpg" po"src="e v>poejkr e <img blah src=\'pic1.gif\' "koklo > po pmoj <img src="pict.php?id=44">'; function my_find_pict($body){ $out = array(); preg_match_all('/<img ([^?]+?)>/',$body,$b); // find <img> tags foreach ($b[1] as $c) { preg_match('/src=["\'](.+?)["\']/',$c,$d);// find src atribute $out[] = $d[1]; } return $out; } $out = my_find_pict($file); print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59065-difficult/#findComment-293513 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.