php短域名转换为实际域名函数
程序员文章站
2022-05-25 21:02:26
复制代码 代码如下: $url = "http://sinaurl.cn/hbdsu5"; echo unshorten($url); function unshorten...
复制代码 代码如下:
$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;
}
上一篇: PHP统计目录下的文件总数及代码行数(去除注释及空行)
下一篇: 女孩子如果遇到劫色,不要慌张