首页  >  文章  >  后端开发  >  php短域名转换为实际域名函数_PHP教程

php短域名转换为实际域名函数_PHP教程

WBOY
WBOY原创
2016-07-21 15:32:181086浏览

复制代码 代码如下:

$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;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/322812.htmlTechArticle复制代码 代码如下: $url = "http://sinaurl.cn/hbdsU5"; echo unshorten($url); function unshorten($url) { $url = trim($url); $headers = get_headers($url); $location = $url; $s...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn