2012-05-07 107 views
0

我使用SimpleXML通過RSS獲取我的推文。我想在推文上點擊鏈接。 但我不知道如何。我嘗試了一些不起作用的東西。 需要您的幫助。如何在推特可點擊的Twitter上創建鏈接RSS

這是我的代碼;

<? 
$twitterRssFeedUrl = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=puzzletravel"; 
$twitterUsername = "puzzletravel"; 
$amountToShow = 5; 

$twitterPosts = false; 
$xml = @simplexml_load_file($twitterRssFeedUrl); 
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; 
$text = $xml; 
if(is_object($xml)){ 
    //Rest of our code will be here 
}else{ 
    die('cannot connect to twitter feed'); 
} 

foreach($xml->channel->item as $twit){ 
    if(is_array($twitterPosts) && count($twitterPosts)==$amountToShow){ 
     break; 
    } 
    $d['title'] = stripslashes(htmlentities($twit->title,ENT_QUOTES,'UTF-8')); 
    $description = stripslashes(htmlentities($twit->description,ENT_QUOTES,'UTF-8')); 
    if(strtolower(substr($description,0,strlen($twitterUsername))) == strtolower($twitterUsername)){ 
     $description = substr($description,strlen($twitterUsername)+1); 
    } 
    $d['description'] = $description; 
    $d['pubdate'] = strtotime($twit->pubDate); 
    $d['guid'] = stripslashes(htmlentities($twit->guid,ENT_QUOTES,'UTF-8')); 
    $d['link'] = stripslashes(htmlentities($twit->link,ENT_QUOTES,'UTF-8')); 
    $twitterPosts[]=$d; 
} 

if(is_array($twitterPosts)){ 
    echo '<ul>'; 
    foreach($twitterPosts as $post){ 
     echo '<li><p>'.$post['description'].'</p><p class="date">'.date(' j F',$post['pubdate']).'</p></li>'; 
    } 
    echo '</ul>'; 
}else{ 
    echo '<p>No Twitter posts have been made</p>'; 
} 

?> 
+0

通過clickable,你的意思是,當用戶點擊該鏈接時,他會轉到該頁面。您可以通過使用''標籤和'href'屬性來做到這一點。 – vedarthk

回答

0

,我發現我的問題的解決方案。這是爲那些可能需要的人提供的解決方案。 該解決方案將包含http,https的文本轉換爲可點擊的網址。

<? 
$twitterRssFeedUrl = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=puzzletravel"; 
$twitterUsername = "puzzletravel"; 
$amountToShow = 7; 

$twitterPosts = false; 
$xml = @simplexml_load_file($twitterRssFeedUrl); 
$reg_exUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; 

if(is_object($xml)){ 
    //Rest of our code will be here 
}else{ 
    die('Tweetler Alinamiyor'); 
} 

foreach($xml->channel->item as $twit){ 
    if(is_array($twitterPosts) && count($twitterPosts)==$amountToShow){ 
     break; 
    } 
    $d['title'] = stripslashes(htmlentities($twit->title,ENT_QUOTES,'UTF-8')); 
    $description = stripslashes(htmlentities($twit->description,ENT_QUOTES,'UTF-8')); 
    if(strtolower(substr($description,0,strlen($twitterUsername))) == strtolower($twitterUsername)){ 
     $description = substr($description,strlen($twitterUsername)+1); 
    } 
    $d['description'] = $description; 
    $d['pubdate'] = strtotime($twit->pubDate); 
    $d['guid'] = stripslashes(htmlentities($twit->guid,ENT_QUOTES,'UTF-8')); 
    $d['link'] = stripslashes(htmlentities($twit->link,ENT_QUOTES,'UTF-8')); 
    $twitterPosts[]=$d; 
} 

if(is_array($twitterPosts)){ 
    echo '<ul>'; 
    foreach($twitterPosts as $post){ 

     if(preg_match($reg_exUrl, $post['description'], $url)) { 
      $post['description']=preg_replace($reg_exUrl, "<a href={$url[0]}>{$url[0]}</a> ", $post['description']); 
     } 

     echo '<ul id="twitter_update_list"> 
       <li> 
    <div id="tweet">'.$post['description'].'<a href="'.$post['link'].'">'.date(' j F',$post['pubdate']).'<br></a></li>'; 
    } 
    echo '</ul>'; 
}else{ 
    echo '<p>Güncel Tweetler Oluşturulamadı Sayfayı Yenilemeyi Deneyin.</p></div>'; 
} 

?> 
0

更改此:

echo '<li><p>'.$post['description'].'</p><p class="date">'.date(' j F',$post['pubdate']).'</p></li>'; 

這樣:

echo '<li><p><a href="'.$post['link'].'">'.$post['description'].'</p><p class="date">'.date(' j F',$post['pubdate']).'</a></p></li>'; 
+0

謝謝你tonymarschall,但它不是我問。 我正在嘗試使'描述'中的鏈接可點擊。 – orko

+0

我解決了我的問題。我會在7小時後將它發佈在這裏。 – orko

+0

對不起,誤解了你的問題。希望你解決了你的問題。 – tonymarschall

相關問題