Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php dom get image src path encode

Tags:

php

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;
    }

}
like image 503
user167043 Avatar asked Nov 06 '12 08:11

user167043


1 Answers

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'));
}
like image 146
NotGaeL Avatar answered Nov 14 '22 01:11

NotGaeL