php短域名转换为实际域名函数
2018-09-07 21:33
阅读:259
复制代码 代码如下:
$url =
echo unshorten($url);
function unshorten($url) {
$url = trim($url);
$headers = get_headers($url);
$location = $url;
$short = false;
foreach($headers as $head) {
if($head==HTTP/1.1 302 Found) $short = true;
if($short && startwith($head,Location: )) {
$location = substr($head,10);
}
}
return $location;
}
function startwith($Haystack, $Needle){
return strpos($Haystack, $Needle) === 0;
}
评论
亲,登录后才可以留言!