如题,返回一个数组,可以获得图片地址的base url,相对地址,名称等,具体见下例:
<?error_reporting(E_ALL ^ E_NOTICE); $imgurl='http://www.vevb.com/file_images/article/201408/201408232212306.png';$imgurl_dir='/img/2014/07/02/14520384.gif';//echo getimg($imgurl,'./img');var_dump(url_set_value($imgurl));var_dump(url_set_value($imgurl_dir));/** * function name:url_set_value * User: Don * Date: 14-8-2 * Time: 上午12:43 */function url_set_value($url) { $a=explode('/',$url);$url_set=array();for($n=0 ;$n<count($a);$n++){ //var_dump($a); if($a[$n]=='http:') { $url_set['base_url']=$a[$n+2]; for($p=$n+3 ;$p<count($a)-1;$p++) $url_set['img_dir_path'].='/'.$a[$p]; $url_set['img_path']= $a[count($a)-1]; $url_set['img_ful_path']= $url_set['img_dir_path'].$url_set['img_path']; } else { for($p=0 ;$p<count($a)-1;$p++) if($a[$p]!=='') $url_set['img_dir_path'].='/'.$a[$p]; $url_set['img_path']= $a[count($a)-1]; $url_set['img_ful_path']= $url_set['img_dir_path'].$url_set['img_path']; } return $url_set;}}?>
运行结果:
array(4) { ["base_url"]=> string(14) "www.vevb.com" ["img_dir_path"]=> string(27) "/file_images/article/201408" ["img_path"]=> string(19) "201408232212306.png" ["img_ful_path"]=> string(46) "/file_images/article/201408201408232212306.png"}array(3) { ["img_dir_path"]=> string(15) "/img/2014/07/02" ["img_path"]=> string(12) "14520384.gif" ["img_ful_path"]=> string(27) "/img/2014/07/0214520384.gif"}
新闻热点
疑难解答