header,这里是浪峰小园子的头部信息,header,未完待续

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

 

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

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

 1 $url = "http://sinaurl.cn/hbdsU5"; 
 2 echo unshorten($url); 
 3 function unshorten($url) { 
 4 $url = trim($url); 
 5 $headers = get_headers($url); 
 6 $location = $url; 
 7 $short = false; 
 8 foreach($headers as $head) { 
 9 if($head=="HTTP/1.1 302 Found") $short = true; 
10 if($short && startwith($head,"Location: ")) { 
11 $location = substr($head,10); 
12 } 
13 } 
14 return $location; 
15 } 
16 function startwith($Haystack, $Needle){ 
17 return strpos($Haystack, $Needle) === 0; 
18 } 

 

 源地址:http://laf.freel.cn/default/phpshorturl.html

 

 

 
posted @ 2013-05-13 10:22  浪峰小园子 -- 比较认真的PHP平台开发  阅读(236)  评论(0编辑  收藏  举报
友情链接: 浪峰小园子-认真PHP平台开发| 博客园-程序员最好的网上家园| 凤凰网-大中华区专业媒体| 小米科技-持续创新力的公司| 36氪-关注互联网创业