帮同学宣传一下http://shop57644665.taobao.com/

在我的wordpress中,根据饭否提供的api,使用php写了一个读取饭否最新的一条消息。为什么不用饭否的wordpress插件呢?因为我只需要简单的读取,不需要那么复杂的应用。

代码如下

<?php
$url = 'http://api.fanfou.com/statuses/user_timeline.xml?count=1';
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERPWD,"ilived.cn@gmail.com:XXXXXX");
ob_start();
curl_exec($ch);
curl_close($ch);
$content = ob_get_contents();
ob_end_clean();
preg_match("#<text>(.*?)</text>#s",$content,$matches);
?>

其中$matches[0]就是最新的消息文本。

例子见右边的About Me