先前看到有人问正常网址转换为短网址,现在想请教各位能把转换后的短网址再还原回来呢...
这是微博一个短网址还原的程序,建议你参考一下:
function shorurl($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 && purl($head,"Location: ")){$location = substr($head,10);}}return $location;}function purl($Haystack, $Needle){return strpos($Haystack, $Needle) === 0;}
function get_real_url($url){$headers = @get_headers($url);$pattern = '/Locations*:s*(https?:[^;snr]+)/i';if($locations = preg_grep($pattern, $headers)){preg_match($pattern, end($locations), $redirect);return $redirect[1];}return $url;}
参考:PHP 还原短网址方法和源码
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
这是微博一个短网址还原的程序,建议你参考一下:
function shorurl($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 && purl($head,"Location: "))
{
$location = substr($head,10);
}
}
return $location;
}
function purl($Haystack, $Needle)
{
return strpos($Haystack, $Needle) === 0;
}
function get_real_url($url){
$headers = @get_headers($url);
$pattern = '/Locations*:s*(https?:[^;snr]+)/i';
if($locations = preg_grep($pattern, $headers)){
preg_match($pattern, end($locations), $redirect);
return $redirect[1];
}
return $url;
}
参考:PHP 还原短网址方法和源码