作者chenyen ()
看板PHP
标题Re: [分享]0rz.net短网址的php函数
时间Sat Jul 8 13:43:11 2006
我把qrttl大大的程式码修改成使用fsockopen这个函式来完成
<?php
function tinyurl($url)
{
$fp = fsockopen("tinyurl.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "connection failed.<br>";
} else {
//$url = '
http://www.google.com.tw';
// set post data
$post_data="url=".urlencode($url);
// make up http talk
$talk = "POST /create.php HTTP/1.0\r\n";
$talk .= "HOST:tinyurl.com\r\n";
$talk .= "Keep-Alive:300\r\n";
$talk .= "Content-Type:application/x-www-form-urlencoded\r\n";
$talk .= "Referer:
http://tinyurl.com/\r\n";
$talk .= "Content-Length:".strlen($post_data)."\r\n\r\n";
$talk .= $post_data;
$talk .= "\r\n\r\n";
// receive html
fwrite($fp, $talk);
while (!feof($fp)) {
$html.= fgets($fp, 128);
}
// parsing html get tiny url
$lines = split("\n", $html);
$line_match = preg_grep("/blockquote.*tinyurl\.com/", $lines);
preg_match('/href="(http.*)" target/', array_shift($line_match),$tiny_url);
return $tiny_url[1];
//echo $tiny_url[1];
fclose($fp);
}
}
?>
PS:
因为没办法使用socket_create等函式
所以我重安装mod_php5
但不知为啥没跳出选单 让我选 @@
後来去安装 php5-extensions 在 makefile修改 with socket=yes
安装後还是一样不能用
不过发现fsockopen可以用....
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.223.167.109
※ 编辑: chenyen 来自: 61.223.167.109 (07/08 13:43)
1F:推 qrtt1:恭禧您也能玩了..cc 07/08 14:07