欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP subistr 截取字符串无码

程序员文章站 2024-01-27 20:42:40
...

更新时间:20120102

  1. /**
  2. * [WebodMin] (C)2010-2099 Blank Inc.
  3. * This is NOT a freeware, use is subject to license terms
  4. *
  5. **/
  6. function subistr($string, $length, $dot = ' ...') {
  7. global $charset;
  8. if(strlen($string) return $string;
  9. }
  10. $s = '';
  11. if(strtolower($charset) == 'utf-8') {
  12. $n = $tn = $noc = 0;
  13. while($n $t = ord($string[$n]);
  14. if($t == 9 || $t == 10 || (32 $tn = 1; $n++; $noc++;
  15. } elseif(194 $tn = 2; $n += 2; $noc += 2;
  16. } elseif(224 $tn = 3; $n += 3; $noc += 2;
  17. } elseif(240 $tn = 4; $n += 4; $noc += 2;
  18. } elseif(248 $tn = 5; $n += 5; $noc += 2;
  19. } elseif($t == 252 || $t == 253) {
  20. $tn = 6; $n += 6; $noc += 2;
  21. } else {
  22. $n++;
  23. }
  24. if($noc >= $length) {
  25. break;
  26. }
  27. }
  28. if($noc > $length) {
  29. $n -= $tn;
  30. }
  31. $s = substr($string, 0, $n);
  32. } else {
  33. for($i = 0; $i $s .= ord($string[$i]) >= 127 ? $string[$i].$string[++$i] : $string[$i];
  34. }
  35. }
  36. return $s.$dot;
  37. }
复制代码