2010-02-22 142 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(); 

注:這是更好地編輯您原來的問題,並添加代碼,而不是添加必要的代碼在別處註釋。這使得其他人更容易找出問題所在。 :-)

相關問題