首页 >后端开发 >php教程 >PHP subistr 截取字符串无码

PHP subistr 截取字符串无码

WBOY
WBOY原创
2016-07-25 09:08:491456浏览

更新时间: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. }
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
上一篇:wecis 2.0 RC 版 下一篇:PHP 简易爬虫