2010-02-22 141 views
0

使用简单的PHP调用和Jquery脚本我在我的网站上显示了我的Twitter提要,它一切正常,但我希望我的推文链接位于标签中在twitter.com上。将<a>标记链接添加到您的Twitter XML Feed

例如XML:

<text>There are over 20,000 design based businesses in London alone - http://icanhaz.com/designbusinesses</text> 

我想获得<a href="...."> .... </a>周围的URL,这样我可以返回HTML这样的:

<p>here are over 20,000 design based businesses in London alone - <a href="http://icanhaz.com/designbusinesses"> ... </a> </p> 

回答

3

一个简单的谷歌搜索想出了下面的代码-snippet改变链接到点击的超链接在PHP中:

http://www.totallyphp.co.uk/code/convert_links_into_clickable_hyperlinks.htm

的代码是:

function makeClickableLinks($text) { 

    $text = eregi_replace('(((f|ht){1}tp://)[-a-z[email protected]:%_\+.~#?&//=]+)', 
    '<a href="\\1">\\1</a>', $text); 
    $text = eregi_replace('([[:space:]()[{}])(www.[[email protected]:%_\+.~#?&//=]+)', 
    '\\1<a href="http://\\2">\\2</a>', $text); 
    $text = eregi_replace('([_\.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', 
    '<a href="mailto:\\1">\\1</a>', $text); 

    return $text; 
} 

它从http改变了一切://到ftp://至mailto:到链接

1

你的问题是,jQuery的text()剔除HTML。改用html()函数。

这是假设,当然,这是你正在使用更新您的Twitter的饲料代码:

var title = $(this).find("text").text(); 

注:这是更好地编辑您原来的问题,并添加代码,而不是添加必要的代码在别处注释。这使得其他人更容易找出问题所在。 :-)

相关问题