Hi,
ive been working on a site which tries to paginate news articles from a database into seperate pages, i made up a little function that would try to disect the chars from the database and split them up into pages.
It has been working OK but not perfectly, line breaks and images seem to cause problems as the page i am told to work with has a fixed depth/height. Also a probelm now is that the database includes markup which my function does not cope for.
I know i can change it and tweak it but i think i might be just redoing what has already been written.
does anybody know of a good uber pagination script that i can use?
thanks in advance,
david.
p.s. here is my code, it took me a while to write but its just not cutting the mustard.
function getThePageText( $stringIn , $page , $pageCharLimit ){
// WHAT CHAR SHOULD WE BE STARTING AT
$ourTheoreticalStartPosition = ( $page * $pageCharLimit ) - $pageCharLimit ;
// WHAT CHAR SHOULD WE BE FINISHING AT
$ourTheoreticalEndPosition = ( $page * $pageCharLimit ) ;
// GET THE THEORETICAL STRING
$ourTheoreticalStartString = substr( $stringIn , 0 , $ourTheoreticalStartPosition ) ;
$ourTheoreticalEndString = substr( $stringIn , 0 , $ourTheoreticalEndPosition ) ;
// WHERE DOES THE PAGE START
//$ourActuallyStartPosition = strrpos( $ourTheoreticalStartString , '.' ) ;
$ourActuallyStartPosition = max(
strrpos( $ourTheoreticalStartString , '.' ),
strrpos( $ourTheoreticalStartString , '?' ),
strrpos( $ourTheoreticalStartString , '!' )
);
// WHERE DOES THE PAGE END
$ourActuallyEndPosition = max(
strrpos( $ourTheoreticalEndString , '.' ),
strrpos( $ourTheoreticalEndString , '!' ),
strrpos( $ourTheoreticalEndString , '?' )
);
if( $ourActuallyStartPosition > 1 ){
// IS NOT THE FIRST PAGE
$outString = substr( $stringIn, $ourActuallyStartPosition + 1 , $ourActuallyEndPosition - $ourActuallyStartPosition + 1 ) ;
}
else{
// IS THE FIRST PAGE
$outString = substr( $stringIn, $ourActuallyStartPosition , $ourActuallyEndPosition - $ourActuallyStartPosition + 1 ) ;
}
// CUT THE STRINGIN AND TAKE OUT THE NTDLRS
return nl2br( $outString ) ;
}