Xeen Xeen - 1 month ago 8
PHP Question

How to split text in 2 halves?

I've done it like so:

if(strlen($block_text) > 2000) {
$half = strlen($block_text)/2;
$second_half = substr($block_text, $half);
$block_text = substr($block_text, 0, $half);
}


but the problem here is that the
$second_half
starts in the middle of a word and the
$block_text
ends in the middle of a word. Could it be possible to tweak it somehow so that the first half ends after a dot
.
?

Answer
if(strlen($block_text) > 2000) {
  $half = strpos($block_text, ".",  strlen($block_text)/2);
  $second_half = substr($block_text, $half);
  $block_text = substr($block_text, 0, $half);
}

Now it will find the first dot after half the text.