应该就是".."补为你的采集url.个人思路:先通过正则过滤出图片url
$pattern = "/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i";(该正则不适合,自己写)
preg_match_all($pattern,$str, $match); //过滤出$str中图片地址判断过滤出的url是否存在"http://"字符串
if(!strstr($match[2],'http://')){
添加采集url
}else{
不做改动.
}

解决方案 »

  1.   

    把相对地址改成绝对地址,替换下,如 $a=str_replace('img/1.jpg','www.xxx.com/img/1.jpg',$a);
      

  2.   

    $url = 'http://topic.csdn.net/u/20090413/17/9829fdf6-4a53-4335-aaf0-da071fdcd462.html';//采集时的url
    $p = parse_url($url);
    $path = split('/', $p['path']);
    $path[0] = $p['host'];
    array_pop($path);print_r($path);//$path是格式化后的路径信息//以下常见的图片路径供测试用
    $img = './img/load/2.jpg';
    $img = '/img/load/2.jpg';
    $img = '../../img/load/2.jpg';
    $img = 'img/load/2.jpg';//分析并配全路径
    $tmp = split('/', $img);
    switch(1) {
      case $tmp[0] == '':
        array_shift($tmp);
        $img = $path[0] .'/'. join('/',$tmp);
        break;
      case $tmp[0] == '.':
        array_shift($tmp);
        $img = join('/', $path) .'/'. join('/',$tmp);
        break;
      case $tmp[0] == '..':
        while(($c=array_shift($tmp)) == '..') {
          array_pop($path);
        }
        array_unshift($tmp, $c);
        $img = join('/', $path) .'/'. join('/',$tmp);
        break;
      default:
        $img = join('/', $path) .'/'. join('/',$tmp);
        break;
    }
    echo $img;