Hi guys.
I'm writing code to generate character-based pagination. I have articles in my site that I want to split up based on length.
The code I have so far is working albeit two issues:
- It's splitting pages in the middle of words and HTML tags; I want it to only split after a complete word, tag, or a punctuation mark.
 - In the pagination bar, it's generating the wrong number of pages.
 
In the pagination bar, it's generating the wrong number of pages.
Need help addressing these two issues. Code follows:
$text = file_get_contents($View);
$ArticleLength = strlen($text);
$CharsPerPage = 5000;
$NoOfPages = round((double)$ArticleLength / (double)$CharsPerPage);
$CurrentPage = $this->ReturnNeededObject('pagenumber');
$Page = (isset($CurrentPage) && '' !== $CurrentPage) ? $CurrentPage : '1';
$PageText = substr($text, $CharsPerPage*($Page-1), $CharsPerPage);
echo $PageText;
?> <p> <?php
for ($i=1;$i < $NoOfPages+1;$i++)
{
 if ($i == $CurrentPage)
 {
 ?>
  <strong> <?php echo $i; ?> </strong>
 <?php
 }
 else
 {
 ?>
 <a href="<?php echo $i; ?>"><?php echo $i; ?></a>
 <?php
 }
 ?> | <?php
}
?> </p>
What am I doing wrong? I think I'm almost there...