Vincent,
here is what i have so far. Skripty did this for me, and well, so far it seems to work. You suggested counting words instead of characters? How would u modify this code to do that?
<?
// for this example i will be reading the data in from a text file.
//first of all lets get a couple of variables set//
//$leftPageNo = 3;//just for testing
$end=false;
if ($leftPageNo == ""){
$leftPageNo = 1;
}
$rightPageNo = $leftPageNo + 1;//this is needed anyway
$charsPerPage = 1200;
$charsPerPageMaster = $charsPerPage; //no. chars per page (for my example it is 893)
//next, we are going to count the no. of chars in the text file.
$fileName = "testChapter.txt"; //the name of the file.
$file_pointer = fopen($fileName, "r");
$data = fread($file_pointer, filesize($fileName));
fclose($file_pointer);
$len=strlen($data); //set $len to the lenght of the file in chars.
$pages = $len/$charsPerPage; //set pages to how many pages there will be.
$pagesTEMP = round($pages); //round the number
if($pagesTEMP < $pages) { //check the number was rounded UP
$pagesTEMP = $pagesTEMP +1; //if not add 1
}
$pages = $pagesTEMP;
?>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="782" border="2" height="455" align="left">
<tr>
<td width="34" height="41"> </td>
<td colspan="2" height="41"> </td>
<td width="34" height="41"> </td>
</tr>
<tr>
<td width="34" height="364"> </td>
<td width="343" height="364" valign="top" align="left">
<p>
<?
//First we will concentrate on displaying the left hand page
$startChar = ($leftPageNo * $charsPerPage)-$charsPerPage;
if($leftPageNo < $pages){ //if this page is not the last page
if($leftPageNo > 1){
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $startChar, 1);
$startChar=$startChar+1;
}
}
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $charsPerPage, 1);
$charsPerPage=$charsPerPage+1;
}
//$leftPageData = ereg_replace("\n", "<br>", $leftPageData);
$leftPageData = substr($data, $startChar, $charsPerPage);
echo $leftPageData;
}
if($leftPageNo == $pages){ //if this page is the last page
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $startChar, 1);
$startChar=$startChar+1;
}
//$leftPageData = ereg_replace("\n", "<br>", $leftPageData);
$leftPageData = substr($data, $startChar);
echo $leftPageData;
}
if($leftPageNo > 1){ // if this page is not the first page
$previousButton = true; // display precious button
}
else{ // if this page is the first page
$previousButton = false;// do not display a previous button
}
?>
</p>
</td>
<td width="341" height="364" align="left" valign="top" nowrap>
<?
//Now we will concentrate on displaying the right hand page
//$charsPerPage=$charsPerPageMaster;
//$startChar = ($rightPageNo * $charsPerPage)-$charsPerPage;
$startChar = $startChar + $charsPerPage;
if($rightPageNo < $pages){ //if this page is not the last page
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $startChar, 1);
$startChar=$startChar+1;
}
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $charsPerPage, 1);
$charsPerPage=$charsPerPage+1;
}
//$rightPageData = ereg_replace("\n", "<br>", $rightPageData);
$rightPageData = substr($data, $startChar, $charsPerPage+1);
echo $rightPageData;
}
if($rightPageNo == $pages){ //if this page is the last page
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $startChar, 1);
$startChar=$startChar+1;
}
$tempChar = "#";
While($tempChar != " "){
$tempChar = substr($data, $charsPerPage, 1);
$charsPerPage=$charsPerPage+1;
}
//$rightPageData = ereg_replace("\n", "<br>", $rightPageData);
$rightPageData = substr($data, $startChar);
echo $rightPageData;
}
if($rightPageNo > $pages){
echo" ";
}
if($rightPageNo < $pages){
if ($end == false){ // if this page is not the last page
$nextButton = true;
}
else{
$nextButton = false;
} // display next button
}
else{ // if this page is the first page
$nextButton = false;// do not display a next button
}
?>
</td>
<td width="34" height="364"> </td>
</tr>
<tr>
<td width="34"> </td>
<td width="343">
<?
if ($previousButton == true){
$prevPage = $leftPageNo - 2;
echo"<a href=\"book.php?leftPageNo=${prevPage}\">Previous</a>";
}
else{
echo" ";
}
?>
</td>
<td width="341"><div align="right">
<?
if ($nextButton == true){
$nextPage = $rightPageNo + 1;
echo"<a href=\"book.php?leftPageNo=${nextPage}\">Next</a>";
}
else{
echo" ";
}
?>
</div></td>
<td width="34"> </td>
</tr>
</table>
</body>