45IT.COM- 电脑学习从此开始!
DIY硬件教程攒机经验装机配置
设计Photoshop网页设计特效
系统注册表DOS系统命令其它
存储主板显卡外设键鼠内存
维修显卡CPU内存打印机
WinXPVistaWin7unix/linux
CPU光驱电源/散热显示器其它
修技主板硬盘键鼠显示器光驱
办公ExcelWordPowerPointWPS
编程数据库CSS脚本PHP
网络局域网QQ服务器
软件网络系统图像安全
页面导航: 首页 > 设计学院 > 网页设计 >

wordpress页面截取中文乱码解决办法

电脑软硬件应用网 45IT.COM 时间:2013-08-09 10:18 作者:佚名

今天提到的程序中截取中文乱码的问题尤其是在首页,对人的第一印象是非常不友好的,现将页面乱码问题的解决方案分享以下所述。

 代码如下  

<?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($StringLast)){
$StringLast = implode("",$StringLast);
$StringLast .= "...";
}
return $StringLast;
}
}
 

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
无法在这个位置找到: baidushare.htm
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐知识