Jump to content

difficult ?


rmoss_uk

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/59065-difficult/
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/59065-difficult/#findComment-293513
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.