PHP 最新推文

标签 php twitter

我创建了一个 twitter 类,其方法根据指定的用户提取最新推文...使用 twitter .XML

class twitter {

// Set twitter basepath
public $basepath = 'http://twitter.com/statuses';

function tweet($username){   

    $xml = new SimpleXMLElement($this->basepath.'/user_timeline/'. $username .'.xml?count=1', NULL, TRUE);
    $status = $xml->status->text;

    return '<b>' . $username . ' says: </b>' . $status;
}

这个 echo 出来了

XXXXX says: @XXXX Moving it up to 10am on Sunday - it's about a 1.5 hour drive.

如何让 php 将“@”标记链接为 HTML 链接而不是文本链接? 有没有办法查找字符串“@”并将剩余的单词替换为 href?

最佳答案

我正在使用这个:

$status = preg_replace('#@(\w+)\b#', '<a href="http://twitter.com/$1">@$1</a>', $status);

关于PHP 最新推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983640/

相关文章:

ios - 防止用户修改 SLComposeViewController 中的部分文本

php - 需要连续检索标题、描述和上传的图像并使用 php 显示它们

php - 如何在 php 中清理从 url 到 mysql 的简单 _GET 输入

php - 如何在 php 生成的 zip 中排除文件

javascript - 将文本添加到 Twitter 推文文本区域

hadoop - Storm Twitter 访问 key 不正确或丢失

api - 创建 API 会给您的服务带来什么好处?

php - 提高(查询)性能

php - PHP 中的 file_exist() 是一项非常昂贵的操作吗?

java - Android 将 Arraylist 数据设置为自定义适配器