Breaking a block of text in half.
Posted: Sat Nov 12, 2005 2:38 pm
I need to split a block of text in to two halfs. I can do this pretty easily using:
However, this only works for plain text. If there's HTML in there it all goes horribly wrong. Anyone got any ideas how to split text into two roughly equal halves and still maintain any HTML in it?
Code: Select all
$midpoint = (strlen($text)/2);
$breakpoint = strpos($text, ". ", $midpoint);
$firsthalf = substr($text, 0, $breakpoint+1);
$secondhalf = substr($text, $breakpoint+1);