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

前端之家收集整理的这篇文章主要介绍了php短域名转换为实际域名函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="98577" class="copybut" id="copybut98577" onclick="doCopy('code98577')"> 代码如下:

<div class="codebody" id="code98577">
$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;
}

原文链接:https://www.f2er.com/php/28177.html

猜你在找的PHP相关文章