Hi there and greetings from the Netherlands,
I have been struggling with this string for days now and don't know what I am missing here. I have this string:
'<img src="C:\TEMP\somewhere\something.jpg" alt="" >bla bla bla some other stuff<img src="C:\TEMP\somewhere\something2.jpg">'
and what I want to retrieve is every filename and pathname of the images and nothing else (no other HTML, no alt tags etc.). In this case that would be:
C:\TEMP\somewhere\something.jpg
C:\TEMP\somewhere\something2.jpg
Attempts so far:
put the whole string in array
do a preg_grep for /(src=(\'|")file.\/(.(.jpg|.gif|.png)))/ in that array
Then I thought I just explode the array items on the double quote, read the second item of the array, but somehow the exploding does not quite work. What am I doing wrong (it's driving me bazerk)?
To be complete, this is my code:
<?php
function Make_Find_Image_Path($HTMLString) {
$HTMLin = explode(">",$HTMLString);
$pattern = '/(src=(\'|")file.\/(.(.jpg|.gif|.png)))/';
$Result_String = preg_grep($pattern,$HTMLin);
foreach($Result_String as $value)
{
return(array_pop(explode('\"',$value))) . "<BR>";
}
}
$HTMLString = '<img src="//somewhere/something.jpg" alt="" >dsafas<img alt="" src="/somewhere/something2.jpg">';
echo Make_Find_Image_Path($HTMLString);
?>
Thanks and any help is appreciated....
Cees