手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2012年05月24日的文章

文章出现乱码怎么办?

文本本来是UTF-8的。但是会出现乱码,类似:
像吉本芭娜娜一æ·ï¼Œåœ¨è¿™ä¸ªä¸–界上,
我最喜欢的地方就是厨房。
—— 李妙生
这种在显示的时候出现很让人郁闷,但不能不解决它,怎么办?写了一个无耻的函数:

XML/HTML代码
  1. function getUtf8Content($content,$default=null){  
  2.         $dContent = utf8_decode($content);  
  3.         if(mb_detect_encoding($dContent) == mb_detect_encoding($content)){//这句话有点妖。多试试就知道了  
  4.             if($default !== null){  
  5.                 $content = $default ;  
  6.             }else{  
  7.                 if(strpos($dContent,"??????")===false){  
  8.                     $content = $dContent;  
  9.                 }  
  10.             }  
  11.         }  
  12.         return $content;  
  13.     }  

不管了,能解决问题就好。。黑黑,不要怕丑

Tags: 乱码