views:

116

answers:

2

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 links 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&lt;/text&gt;

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"&gt; ... </a> </p>
+3  A: 

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"&gt;\\2&lt;/a&gt;', $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

Pbirkoff
Thanks but this doesn't really solve my problem as my Jquery call still stips out the <a> tag...var title = $(this).find("text").text();
Rob B
Then you should show the snippet of the jquery code that you're using which does this and we can help you fix it.
Steve Kemp
+1  A: 

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. :-)

Sean Vieira