I use below codes to extract image src path .but this is a problem when the image filename has special character(eg:~ DQBTZ_UC(G@STWO_1R2U_Q4.gif),the output turn to be like this :~ 6Z6W4%255BO29FQ%255BA4YN_%255BFR9%2529M.gif
How to fix this issue? sorry for my poor English.
function _get_imagepath($content){
$doc = new DOMDocument();
$doc->loadHTML($content);
$imagepaths=array();
$imageTags = $doc->getElementsByTagName('img');
$folder=file_directory_path();
foreach($imageTags as $tag) {
$imagepaths[]=$tag->getAttribute('src');
}
if(!empty($imagepaths)){
return $imagepaths;
}else{
return FALSE;
}
}
It seems your filenames are URL encoded. Take a look at http://php.net/manual/en/function.urldecode.php
i.e:
foreach($imageTags as $tag) {
$imagepaths[]=urldecode($tag->getAttribute('src'));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With