慕粉1461415760
2016-05-27 20:39
curl怎么抓取相对路径???
可以写一个函数将相对路径变成绝对路径就行拉 比如说:
function format_url($srcurl, $baseurl) { $srcinfo = parse_url($srcurl); if(isset($srcinfo['scheme'])) { return $srcurl; } $baseinfo = parse_url($baseurl); $url = $baseinfo['scheme'].'://'.$baseinfo['host']; if(substr($srcinfo['path'], 0, 1) == '/') { $path = $srcinfo['path']; }else{ $path = dirname($baseinfo['path']).'/'.$srcinfo['path']; } $rst = array(); $path_array = explode('/', $path); if(!$path_array[0]) { $rst[] = ''; } foreach ($path_array AS $key => $dir) { if ($dir == '..') { if (end($rst) == '..') { $rst[] = '..'; }elseif(!array_pop($rst)) { $rst[] = '..'; } }elseif($dir && $dir != '.') { $rst[] = $dir; } } if(!end($path_array)) { $rst[] = ''; } $url .= implode('/', $rst); return str_replace('\\', '/', $url); } $a = 'http://shijinrong.cn'; $b = '/home/article/tags.html'; echo format_url($b, $a);
来自网络
PHP中的数据传输神器cURL
34277 学习 · 218 问题
相似问题