Home  >  Article  >  php教程  >  php短域名转换为实际域名函数

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

WBOY
WBOYOriginal
2016-06-06 20:35:491037browse

现在很多朋友需要将实际域名转换为短域名,但也有朋友需要反转查看下实际域名,那么就可以使用这个函数。

复制代码 代码如下:


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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn