function Limit_Char($max_char = 200, $more_text = '...', $more_link_text = '', $limit_type = 'content') {
if ($limit_type == 'title') { $limiter = get_the_title(); }
else { $limiter = get_the_content(); }
$limiter = apply_filters('the_content', $limiter);
$limiter = strip_tags(str_replace(']]>', ']]>', $limiter));
if (strlen($limiter) > $max_char) {
$limiter = substr($limiter, 0, $max_char+1);
$limiter = utf8_conver($limiter);
echo $limiter;
echo $more_text;
if ($more_link_text != '') {
echo ' <a href="';
echo the_permalink();
echo '">'.$more_link_text.'</a>';
}
} else {
echo $limiter;
}
}
function utf8_conver($str) {
$len = strlen($str);
for ($i=strlen($str)-1; $i>=0; $i-=1){
$hex .= ' '.ord($str[$i]);
$ch = ord($str[$i]);
if (($ch & 128)==0) return(substr($str,0,$i));
if (($ch & 192)==192) return(substr($str,0,$i));
}
return($str.$hex);
}
<?php Limit_Char(200); ?>
<!-- 200是你需求截断多少字节的长度,依据实际状况修正。-->
以上就是安达网络工作室关于《wordpress中文截断产生乱码解决方法》的一些看法。更多内容请查看本栏目更多内容!
1.增加性能 在function.php中拔出代码 add_theme_support('post-thumbnails'); 拔出之后会在后盾编辑文章的...
一 wordpress装置 我用的是XAMPP(Apache+MySql+PHP),wordpress(BLOG顺序)3.5.1 简体中武官方装置版...
渣滓评论曾经不是一个新颖的货色了,置信只需是日独立IP超越2000的网站,只需开放评论的话,每天都会收到几...
函数引见 update_option()用于更新数据表中存在的选项值。该函数可取代add_option,但不迭add_option灵敏。...
在 PHP 中发送 Http 申请(GET / POST)有很多的办法,比方 file_get_contents() 函数、fopen() 函数或许 c...
本文实例讲述了WordPress中增加语音搜寻性能的完成办法。分享给大家供大家参考。详细剖析如下: WordPress能...