I'm using a very simple PHP include to grab my current twitter status and output the content into my website. The trouble though, is that the output doesn't generate links like the actual status does when there are URLs in the status.
What is the best or simplest way to make this happen?
Here's the PHP I'm using to populate the status:
<?php
$response = new SimpleXMLElement('http://twitter.com/users/show/jglovier.xml',NULL,TRUE);
echo $response->开发者_开发问答status->text.'';
?>
*EDIT: since I'm only a front-end developer most comfortable with HTML, CSS, and barely JS, I'm looking for the simplest fix here, preferably JS based.
Try using bcherry/twitter-text-js. It will autolink URLs, @mentions, and #hashtags to the specification that twitter.com uses.
Put twitter-text.js on your server, load it after you load jQuery, and run the snippet below on document ready.
$('p.status').each(function(index, element) {
$(element).html(twttr.txt.autoLink($(element).text()));
});
It's actually a really easy few lines of code:
function twitterify($ret) { $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t\\2", $ret); $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r\\2", $ret); $ret = preg_replace("/@(\w+)/", "@\\1", $ret); $ret = preg_replace("/#(\w+)/", "#\\1", $ret); return $ret; }
Source: http://www.snipe.net/2009/09/php-twitter-clickable-links
I presume you've already solved this as it's been a while since it was posted, but for users wanting to do something similar, I've found this very useful: http://remysharp.com/2007/05/18/add-twitter-to-your-blog-step-by-step/
Brings in your tweets (as many or few as you specify), but the best thing is, you write out the template of how the tweet is displayed - so time/tweet/poster or poster/tweet/time etc.
Very cool!
精彩评论