wordpress页面截取中文乱码解决办法
今天提到的程序中截取中文乱码的问题尤其是在首页,对人的第一印象是非常不友好的,现将页面乱码问题的解决方案分享以下所述,实例代码如下:
<?php echo mb_strimwidth( strip_tags (apply_filters( 'the_content' , $post ->post_content)), 0, 330, "..." ); ?>以上是wordpress中的源代码,这段代码没有处理好中文的截取问题(老外的开源东西竟然没有考虑到china这个大用户).解决方案如下:
<?php echo mb_strimwidth( strip_tags (apply_filters( 'the_content' , $post ->post_content)), 0, 330, "..." , "utf-8" ); ?>涉及到的php文件有:archive.php category.php index.php sidebar-category.php sidebar-single.php(文件在外观–>编辑里面)
给你一个php中文截取函数,代码如下:
function SubTitle( $String , $Length ) { if (mb_strwidth( $String , 'UTF8' ) <= $Length ){ return $String ; } else { $I = 0; $len_word = 0; while ( $len_word < $Length ){ $StringTMP = substr ( $String , $I ,1); if ( ord( $StringTMP ) >=224 ){ $StringTMP = substr ( $String , $I ,3); $I = $I + 3; $len_word = $len_word + 2; } elseif ( ord( $StringTMP ) >=192 ){ $StringTMP = substr ( $String , $I ,2); $I = $I + 2; $len_word = $len_word + 2; } else { $I = $I + 1; $len_word = $len_word + 1; } $StringLast [] = $StringTMP ; } /* raywang edit it for dirk for (es/index.php)*/ if ( is_array ( $StringLast ) && ! empty empty ( $StringLast )){ $StringLast = implode( "" , $StringLast ); $StringLast .= "..." ; } return $StringLast ; } }查看更多关于wordpress页面截取中文乱码解决办法 - WordPress的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did8593