我创建了一个 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/