I have a string which is in special language character.
先秦兩漢先秦兩漢先秦兩漢漢先秦兩漢漢先秦兩漢( 243071)
My requirement is to make it an array in case the character limit exceeds my requirement using php. Like if it exceeds say 15 characters.
For that, I have tried
if(mb_strlen($string) > 15){
$seed = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
}
But it is breaking. It is not breaking for all the cases but for the one has 35 chars.
Another approach I have tried is using this function:-
function word_chunk($str, $len = 76, $end = "||") {
$pattern = '~.{1,' . $len . '}~u'; // like "~.{1,76}~u"
$str = preg_replace($pattern, '$0' . $end, $str);
return rtrim($str, $end);
}
Please help and understand that I need help for MB characters only