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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?