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

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

$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无限极分类函数的实现方法详解

PHP无限极分类函数的实现方法详解

本文实例讲述了PHP无限极分类函数的实现方法。分享给大家供大家参考,具体如下: 在开发程序的时候,有时候,我们需要获取所有栏目(包括一级栏目、二级栏目、三级栏目等等),并按照父子关系形成...

php MsSql server时遇到的中文编码问题

但导到sqlserver 2005后,发现其中文编码只支持GB 和 UCS-2(unicode 16),所以直接在数据库中查询显示正确,但使用php的utf9编码显示时则全是乱码。找了大...

Uncaught exception com_exception with message Failed to create COM object

Uncaught exception com_exception with message Failed to create COM object

在PHP中调用IE使用如下代码: 复制代码 代码如下: browser = new COM("InternetExplorer.Application"); 无法正常调用,直接报错:...

不要轻信 PHP_SELF的安全问题

复制代码 代码如下:<html> <body> <?php if (isset($_REQUEST['submitted']) && $_REQUEST['...

php XMLWriter类的简单示例代码(RSS输出)

复制代码 代码如下: include 'mysql.php'; $mysql= mysql::getObject(); $mysql->query("SELECT * FROM p...