duanhe4267 2012-05-04 11:29
浏览 37
已采纳

如何阻止我的推文代码输出撇号为'

I am using the below functions to create a twitter feed. You can see the results in the footer of my portfolio at nicolaelvin.com. How do I get rid of that ' and make it an apostrophe?

function twitify($str){
                $str = preg_replace("#(^|[
 ])([\w]+?://[\w]+[^ \"
\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $str);
                $str = preg_replace("#(^|[
 ])((www|ftp)\.[^ \"\t
< ]*)#", "\\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>';
        }

    }
  • 写回答

2条回答 默认 最新

  • dongxia1390 2012-05-04 11:46
    关注

    I don't know what is exactly the problem. But I think the encoding is caused by the "htmlentities()" function. Look here for correct syntax.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?