国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > CMS > Wordpress > 正文

wordpress頁(yè)面截取中文亂碼解決辦法

2024-09-07 00:50:12
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

今天提到的程序中截取中文亂碼的問(wèn)題尤其是在首頁(yè),對(duì)人的第一印象是非常不友好的,現(xiàn)將頁(yè)面亂碼問(wèn)題的解決方案分享以下所述,實(shí)例代碼如下:

  1. <?php  
  2. echo mb_strimwidth(strip_tags(apply_filters('the_content'$post->post_content)), 0, 330,"..."); 
  3.  ?> 

以上是wordpress中的源代碼,這段代碼沒(méi)有處理好中文的截取問(wèn)題(老外的開(kāi)源東西竟然沒(méi)有考慮到china這個(gè)大用戶).解決方案如下:

  1. <?php  
  2. echo mb_strimwidth(strip_tags(apply_filters('the_content'$post->post_content)), 0, 330,"...", "utf-8");  
  3. ?> 

涉及到的php文件有:archive.php  category.php  index.php  sidebar-category.php  sidebar-single.php(文件在外觀–>編輯里面)

給你一個(gè)php中文截取函數(shù),代碼如下:

  1. function SubTitle($String,$Length) { 
  2. if (mb_strwidth($String'UTF8') <= $Length ){ 
  3. return $String
  4. }else
  5. $I = 0; 
  6. $len_word = 0; 
  7. while ($len_word < $Length){ 
  8. $StringTMP = substr($String,$I,1); 
  9. if ( ord($StringTMP) >=224 ){ 
  10. $StringTMP = substr($String,$I,3); 
  11. $I = $I + 3; 
  12. $len_word = $len_word + 2; 
  13. }elseif( ord($StringTMP) >=192 ){ 
  14. $StringTMP = substr($String,$I,2); 
  15. $I = $I + 2; 
  16. $len_word = $len_word + 2; 
  17. }else
  18. $I = $I + 1; 
  19. $len_word = $len_word + 1; 
  20. $StringLast[] = $StringTMP
  21. /* raywang edit it for dirk for (es/index.php)*/ 
  22. if (is_array($StringLast) && !emptyempty($StringLast)){ 
  23. $StringLast = implode("",$StringLast); 
  24. $StringLast .= "..."
  25. return $StringLast

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 曲周县| 上虞市| 合阳县| 拜泉县| 偏关县| 增城市| 河间市| 华安县| 棋牌| 若羌县| 简阳市| 资源县| 衡阳市| 赤壁市| 睢宁县| 湟源县| 天长市| 临高县| 贺兰县| 南通市| 信丰县| 夏邑县| 平塘县| 九寨沟县| 宁晋县| 土默特左旗| 天全县| 湘乡市| 泰州市| 尚义县| 射洪县| 新乡县| 平舆县| 达尔| 六枝特区| 瓦房店市| 长岛县| 平远县| 治县。| 七台河市| 正镶白旗|