2012-05-04 3 views
0

私は以下の機能を使ってTwitterフィードを作成しています。結果はnicolaelvin.comのポートフォリオのフッターに表示されます。それを取り除き、それをアポストロフィにするにはどうすればいいですか?アポストロフィを出力する私のtwitterコードを停止する方法'

function twitify($str){ 
       $str = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $str); 
       $str = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $str); 
       $str = preg_replace("/@(\w+)/", "@<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">\\1</a>", $str); 
       $str = preg_replace("/#(\w+)/", "#<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">\\1</a>", $str); 
       return $str; 
     } 

    function twitter(){ 

     $twitterRssFeedUrl = "http://twitter.com/statuses/user_timeline/nicolaElvin.rss"; 
     $twitterUsername = "nicolaElvin"; 
     $amountToShow = 5; 
     $twitterPosts = false; 
     $xml = @simplexml_load_file($twitterRssFeedUrl); 
     if(is_object($xml)){ 
      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; 
      } 
     }else{ 
      die('cannot connect to twitter feed'); 
     } 

     if(is_array($twitterPosts)){ 


      echo '<ul>'; 
      foreach($twitterPosts as $post){ 
       $description=twitify($post['description']); 

       echo '<li><time>'.date('F j, Y, g:i a',$post['pubdate']).'</time></li><li>'.$description.'</li>'; 
      } 
      echo '</ul>'; 
     }else{ 
      echo '<p>No Twitter posts have been made</p>'; 
     } 

    } 

答えて

1

私は正確に何が問題なのか分かりません。しかし、私はエンコーディングが "htmlentities()"関数によって引き起こされると思います。正しい構文についてはhereを参照してください。

+0

偉大な、あなたはその機能を使用する必要はありませんので、それを適応させる方法を提案できますか?つまり、私はstripslashの引数とhtmlspecialcharsの引数は何か分かりません。 – Nicola

+0

私は$ description = str_replace( "'"、 "'"、$ description);で置き換えるようになりました。しかしそれは効果がありません – Nicola

+0

ENT_QUOTESの代わりにENT_NOQUOTESを試してください – webber2k6

1

あなたはRSSを使用しており、htmlentitiesなどの関数を正しく使用していない、非常に古くなったAPIエンドポイントを使用しています。

正しいAPIエンドポイント(https://api.twitter.com/1/statuses/user_timeline.json)を使用し、RSSの代わりにJSONを使用し、実際にデータを表示するまでhtmlentitiesで気にすることはお勧めしません。

あなたはツイートにURL正規表現を使用していますが、すべてのURLがt.co URLになっているため、http://

で始まらないURLを探すのは面倒です
+0

そうですね、実際には私のつぶやきをロードするために実際に働いていた機能を見つけることができませんでした。 – Nicola

+0

もっと良い方法を提案できますか? – Nicola

+0

'$ data = @json_decode(file_get_contents( 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=nicolaElvin')); –

関連する問題