首页 > 开发 > PHP > 正文

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

2024-05-04 22:08:07
字体:
来源:转载
供稿:网友
代码如下:
$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;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表