-
- /**
- * Split string
- * @param String $str The string to be split
- * @param int $length The specified length
- * @param String $end The content appended to the split string block
- */
- function mb_chunk_split($string, $length, $end, $once = false){
- $string = iconv('gb2312', 'utf- 8//ignore', $string);
- $array = array();
- $strlen = mb_strlen($string);
- while($strlen){
- $array[] = mb_substr($string, 0, $length , "utf-8");
- if($once)
- return $array[0] . $end;
- $string = mb_substr($string, $length, $strlen, "utf-8");
- $strlen = mb_strlen($string);
- }
- return implode($end, $array);
- }
-
- $str = 'sThe dfs will arrive at $@# soon';
- $str1 = 'aabbccddeefff' ;
- echo mb_chunk_split($str, 3, '...', true); //sJune 1st...soon$...df...s is coming to...$@#...
- echo "
";
- echo mb_chunk_split($str1, 2, '...'); //aa...bb...cc...dd...ee...ff.. .f
Copy code
|