|
Posted by Peter Parker on 06/02/07 03:07
I tried to do pagination of an article with an arbitrary 2500 characters per
page but if
the cutoff point is not the end of a paragraph (<br><br>), it would be moved
there instead. I am using php5. Here is the skeleton of my code:
$length = strlen($article);
$charsPerPage = 2500;
$numberOfPages = ceil($length/$charsPerPage);
$start = 0;
for($counter=1;counter<$numberOfPages + 1;$counter++) {
$cutOffPoint= strripos(substr($all, $start, $charsPerPage),
'<br><br>');
$pageContent = substr($article, $start, $cutOffPoint-$start);
$start = $cutOffPoint;
echo "page".counter." = ".$pageContent;
}
However, it only works for the first loop for some reason. In the
subsequent loop the $cutOffPoint is located even before the $start (visible
when I
print them out for testing purpose). Could someone show me what I am
missing?
Thanks.
[Back to original message]
|