Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.