0
$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

3 Answers 3

4

You can use strpos()

$pieceLength = strpos($string," ",12);

http://php.net/manual/en/function.strpos.php

2

something like this:

while ($string[$pieceLength]!=' ' || $string[$pieceLength]!='\n')
   $pieceLength++;

substr($string, $pageNo, $pieceLength);

Also consider php builtin wordwrap

0

Look at strpos(); offset would be $pieceLength, but position returned is still from beginning of the haystack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.