Ok, now I need to output the splitted text. So far I came out with the following (I used a single carriage return to save space):
$input = '111 - aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
222 - bbbbbbbbbbbbbbbbbbbbbbbbbbb
333 - ccccccccccccccccccccccccccccccccccccc
444 - dddddddddddddddddddddddddddddddd
555 - eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
666 - ffffffffffffffffffffffffffff
777 - gggggggggggggggggggggggggggggggggggggggggggggggg
888 - jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
999 - kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk';
$parts = preg_split('/\r\n/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$paragraphs_per_page = 2;
// calculate the number of pages
$page_num = ceil(count($parts) / $paragraphs_per_page);
// now let's test it!
$page = 4;
$output = array_slice($parts, ($page - 1) * $paragraphs_per_page, $paragraphs_per_page);
// join the splitted paragraphs and output the text
echo implode('<br /><br />', $output);
And the output is:
777 - gggggggggggggggggggggggggggggggggggggggggggggggg
888 - jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
Works like a charm but I'm still a bit unsure whether or not it's a good solution as the whole thing seems slow to me...