当前位置:首页 > PHP教程 > PHP高级教程

php短域名转换为实际域名函数

复制代码 代码如下:

$url = "http://sinaurl.cn/hbdsu5";
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;
}

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!