Using a simple PHP call and Jquery script I'm displaying my twitter feed on my site, it all works fine but I'd like the l开发者_Go百科inks on my tweets to be in tags like on twitter.com.
example XML:
<text>There are over 20,000 design based businesses in London alone - http://icanhaz.com/designbusinesses</text>
I'd like to get <a href="...."> .... </a>
around the URL so I can return HTML like this:
<p>here are over 20,000 design based businesses in London alone - <a href="http://icanhaz.com/designbusinesses"> ... </a> </p>
A simple Google-search came up with the following code-snippet to change links into a clickable hyperlink in PHP:
http://www.totallyphp.co.uk/code/convert_links_into_clickable_hyperlinks.htm
The code is:
function makeClickableLinks($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $text);
return $text;
}
It changes everything from http:// to ftp:// to mailto: into a link
The problem you have is that jQuery's text()
strips out HTML. Use the html()
function instead.
This is assuming of course that this is the code you are using to update your twitter feed:
var title = $(this).find("text").text();
NB: It's better to edit your original question and add code, rather than adding the essential code in comments elsewhere. It makes it easier for others to figure out exactly what the problem is. :-)
精彩评论