I\'m trying to split strings in half, and it should not split in the middle of a word.
So far I came up with the following which is 99% working :
$te
I was created a great solution, where we dont lost characters or Where the word is not cut wrongly.
function split_title_middle ( $title ) {
$title = strip_tags( $title );
$middle_length = floor( strlen( $title ) / 2 );
$new_title = explode( '
', wordwrap( $title, $middle_length, '
') );
if (isset( $new_title[2] ) ) {
$new_title[1] .= ' ' . $new_title[2];
unset( $new_title[2] );
}
return $new_title;
}
// how to use
$title = split_title_middle( $title );
echo $title[0] . '' . $title[1] . '';