中药方大全小图标
您当前的位置:首页 > 其他 > 网站日记

用于采集的函数,补全url

提示: 阅读权限:公开  来源:原创  作者:中药方大全

用于采集的函数,补全url

// 根据url补全地址 
function formaturl($url, $str){
    if (is_array($str)) {
        $return = array();
        foreach ($str as $href) {
            $return[] = formaturl($url, $href);
        }
        return $return;
    } else {
        if (stripos($str, 'http://')===0 || stripos($str, 'ftp://')===0 || stripos($str, 'https://')===0) {
            return $str;
        }
        $str = str_replace(chr(92), '/', $str);
        $parseUrl = parse_url(dirname($url).'/');
        $scheme = isset($parseUrl['scheme']) ? $parseUrl['scheme'] : 'http';
        $host = $parseUrl['host'];
        $path = isset($parseUrl['path']) ? $parseUrl['path'] : '';
        $port = isset($parseUrl['port']) ? $parseUrl['port'] : '';
        if (strpos($str, '/')===0) {
            return $scheme.'://'.$host.$str;
        } else {
            $part = explode('/', $path);
            array_shift($part);
            $count = substr_count($str, '../');
            if ($count>0) {
                for ($i=0; $i<=$count; $i++) {
                    array_pop($part);
                }
            }
            $path = implode('/', $part);
            $str = str_replace(array('../','./'), '', $str);
            $path = $path=='' ? '/' : '/'.trim($path,'/').'/';
            return $scheme.'://'.$host.$path.$str;
        }        
    }
 }


tags: 采集
返回顶部
推荐资讯
视频:田纪钧讲关节不痛的秘密、膝关节拉筋法
视频:田纪钧讲关节不
白露到了,你还好吗?
白露到了,你还好吗?
尿疗与断食
尿疗与断食
给风疹反复发作女孩的药方(组图)
给风疹反复发作女孩的
相关文章
栏目更新
栏目热门
  1. 帝国cms全站搜索的分页格式如何修改-流程
  2. libreoffice7的命令大全
  3. 帝国cms插件之标题生成标题图片
  4. 帝国cms插件安装模板
  5. useragent两千条,爬虫专用
  6. 帝国cms插件如何兼容gbk和utf8
  7. 帝国cms插件之迅搜
  8. 帝国cms用户上传文件名的命名规则及修改方
  9. 帝国cms7.2函数大全
  10. 帝国cms代码片段备忘录