由于微博中有字数限制,所以如果你发的是网址,会自动将其变为短网址。这里我们把短网址还原为实际网址。请参照下面的程序,用php将微博短地址还原为实际网址方法实现:
<?php
$url= " http://163.fm/1QLJ8U";
echounshorten($url);
functionunshorten($url)
{
$url= trim($url);
$headers= get_headers($url);
$location= $url;
$short= false;
foreach($headersas$head)
{
if($head=="HTTP/1.1 302 Found")
$short= true;
if($short&& startwith($head,"Location: "))
{
$location= substr($head,10);
}
}
return$location;
}
functionstartwith($Haystack, $Needle)
{
returnstrpos($Haystack, $Needle) === 0;
}
?>程序运行结果如下:
http://www.scutephp.com/
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号