找到并打开/source/function/function_core.php,寻找到827行: 
- function dstrlen($str) {
 
 -         if(strtolower(CHARSET) != 'utf-8') {
 
 -                 return strlen($str);
 
 -         }
 
 -         $count = 0;
 
 -         for($i = 0; $i < strlen($str); $i++){
 
 -                 $value = ord($str[$i]);
 
 -                 if($value > 127) {
 
 -                         $count++;
 
 -                         if($value >= 192 && $value <= 223) $i++;
 
 -                         elseif($value >= 224 && $value <= 239) $i = $i + 2;
 
 -                         elseif($value >= 240 && $value <= 247) $i = $i + 3;
 
 -                 }
 
 -                 $count++;
 
 -         }
 
 -         return $count;
 
 - }
 
  复制代码 
写这个函数的,你在我注明红色的地方加了$count++;是几个意思啊,表示非常汗,其实这个函数写的很好了,都已经解决问题了,就因为你老人家加了这个,全部功能失效。大家把这个去掉,就修改好了PHP部分了。 
修改成以下: 
- function dstrlen($str) {
 
 -         if(strtolower(CHARSET) != 'utf-8') {
 
 -                 return strlen($str);
 
 -         }
 
 -         $count = 0;
 
 -         for($i = 0; $i < strlen($str); $i++){
 
 -                 $value = ord($str[$i]);
 
 -                 if($value > 127) {
 
 -                         if($value >= 192 && $value <= 223) $i++;
 
 -                         elseif($value >= 224 && $value <= 239) $i = $i + 2;
 
 -                         elseif($value >= 240 && $value <= 247) $i = $i + 3;
 
 -                 }
 
 -                 $count++;
 
 -         }
 
 -         return $count;
 
 - }
 
  复制代码 
 
 
 
接下来是Javascript部分修改,让浏览器判断正确的标题字数。 
找到并打开/static/js/common.js,找到112行: 
- function mb_strlen(str) {
 
 -         var len = 0;
 
 -         for(var i = 0; i < str.length; i++) {
 
 -                 len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
 
 -         }
 
 -         return len;
 
 - }
 
  复制代码 
修改成: 
- function mb_strlen(str) {
 
 -         var len = 0;
 
 -         var strValue = '';
 
 -         for(var i = 0; i < str.length; i++) {
 
 -                 strValue = str.charCodeAt(i);
 
 -                 if(strValue > 127) {
 
 -                         if(strValue >= 192 && strValue <= 223) i++;
 
 -                         else if(strValue >= 224 && strValue <= 239) i = i + 2;
 
 -                         else if(strValue >= 240 && strValue <= 247) i = i + 3;
 
 -                 }
 
 -                 len++;
 
 -         }
 
 -         return len;
 
 - }
 
  复制代码 
 
 
 
继续找到127行: 
- function mb_cutstr(str, maxlen, dot) {
 
 -         var len = 0;
 
 -         var ret = '';
 
 -         var dot = !dot ? '...' : dot;
 
 -         maxlen = maxlen - dot.length;
 
 -         for(var i = 0; i < str.length; i++) {
 
 -                 len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
 
 -                 if(len > maxlen) {
 
 -                         ret += dot;
 
 -                         break;
 
 -                 }
 
 -                 ret += str.substr(i, 1);
 
 -         }
 
 -         return ret;
 
 - }
 
  复制代码 
修改成: 
- function mb_cutstr(str, maxlen, dot) {
 
 -         var len = 0;
 
 -         var ret = '';
 
 -         var dot = !dot ? '...' : dot;
 
 -         var strValue = '';
 
 -         maxlen = maxlen - dot.length;
 
 -         for(var i = 0; i < str.length; i++) {
 
 -                 strValue = str.charCodeAt(i);
 
 -                 if(strValue > 127) {
 
 -                         if(strValue >= 192 && strValue <= 223) i++;
 
 -                         else if(strValue >= 224 && strValue <= 239) i = i + 2;
 
 -                         else if(strValue >= 240 && strValue <= 247) i = i + 3;
 
 -             }
 
 -             len++;
 
 -                 if(len > maxlen) {
 
 -                         ret += dot;
 
 -                         break;
 
 -                 }
 
 -                 ret += str.substr(i, 1);
 
 -         }
 
 -         return ret;
 
 - }
 
  复制代码 
 
 
 
继续找到1756行: 
- function strLenCalc(obj, checklen, maxlen) {
 
 -         var v = obj.value, charlen = 0, maxlen = !maxlen ? 200 : maxlen, curlen = maxlen, len = strlen(v);
 
 -         for(var i = 0; i < v.length; i++) {
 
 -                 if(v.charCodeAt(i) < 0 || v.charCodeAt(i) > 255) {
 
 -                         curlen -= charset == 'utf-8' ? 2 : 1;
 
 -                 }
 
 -         }
 
 -         if(curlen >= len) {
 
 -                 $(checklen).innerHTML = curlen - len;
 
 -         } else {
 
 -                 obj.value = mb_cutstr(v, maxlen, 0);
 
 -         }
 
 - }
 
  复制代码 
修改成: 
- function strLenCalc(obj, checklen, maxlen) {
 
 -         var v = obj.value, charlen = 0, maxlen = !maxlen ? 200 : maxlen, curlen = 0, strValue = '';
 
 -         for(var i = 0; i < v.length; i++) {
 
 -                 strValue = v.charCodeAt(i);
 
 -                 if(strValue > 127) {
 
 -                         if(strValue >= 192 && strValue <= 223) i++;
 
 -                         else if(strValue >= 224 && strValue <= 239) i = i + 2;
 
 -                         else if(strValue >= 240 && strValue <= 247) i = i + 3;
 
 -                 }
 
 -                 curlen++;
 
 -         }
 
 -         if(maxlen >= curlen) {
 
 -                 $(checklen).innerHTML = maxlen - curlen;
 
 -         } else {
 
 -                 obj.value = mb_cutstr(v, maxlen, 0);
 
 -         }
 
 - }
 
  复制代码 
 
 
 
如果开启了门户的话,找到并打开/static/js/portal.js,找到329行按照上面修改最后一部分的function strLenCalc修改就好了 |