国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 鹤壁市| 岳阳县| 铁岭县| 嘉黎县| 开远市| 额尔古纳市| 泉州市| 平谷区| 凤山市| 林口县| 丰城市| 清新县| 高陵县| 阿勒泰市| 依兰县| 安庆市| 金湖县| 沂源县| 涿州市| 肃宁县| 沿河| 佛山市| 丰镇市| 武川县| 田东县| 稻城县| 苏尼特右旗| 大方县| 都兰县| 文安县| 固镇县| 开化县| 和平区| 星子县| 历史| 肇源县| 乐平市| 弋阳县| 武汉市| 平昌县| 拉萨市|