PHP pagination script
-
22-07-2019 - |
Question
$string = "This is my page content. This text will be paginated.";
$pageNo = "0";
$pieceLength = "12";
$preparedForPrint = substr($string,$pageNo,$pieceLength);
what i want to do is if the 12th character is inside a word(the 12th character is not a space) i want to move my cursor 'till it finds a space an return that substring despite the fact that is more than 12 characters long. how can i do that? thanks
Solution
something like this:
while ($string[$pieceLength]!=' ' || $string[$pieceLength]!='\n')
$pieceLength++;
substr($string, $pageNo, $pieceLength);
Also consider php builtin wordwrap
OTHER TIPS
You can use strpos()
$pieceLength = strpos($string," ",12);
Look at strpos(); offset would be $pieceLength
, but position returned is still from beginning of the haystack.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow