Home > Backend Development > PHP Tutorial > The php mb_chunk_split function supports wide character splitting

The php mb_chunk_split function supports wide character splitting

WBOY
Release: 2016-07-25 08:55:03
Original
2130 people have browsed it
  1. /**
  2. * Split string
  3. * @param String $str The string to be split
  4. * @param int $length The specified length
  5. * @param String $end The content appended to the split string block
  6. */
  7. function mb_chunk_split($string, $length, $end, $once = false){
  8. $string = iconv('gb2312', 'utf- 8//ignore', $string);
  9. $array = array();
  10. $strlen = mb_strlen($string);
  11. while($strlen){
  12. $array[] = mb_substr($string, 0, $length , "utf-8");
  13. if($once)
  14. return $array[0] . $end;
  15. $string = mb_substr($string, $length, $strlen, "utf-8");
  16. $strlen = mb_strlen($string);
  17. }
  18. return implode($end, $array);
  19. }
  20. $str = 'sThe dfs will arrive at $@# soon';
  21. $str1 = 'aabbccddeefff' ;
  22. echo mb_chunk_split($str, 3, '...', true); //sJune 1st...soon$...df...s is coming to...$@#...
  23. echo "
    ";
  24. echo mb_chunk_split($str1, 2, '...'); //aa...bb...cc...dd...ee...ff.. .f
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template