$string = "This is my page content. This text will be paginated.";
$pageNo = "0";
$pieceLength = "12";  

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

我想要做的是,如果12字符是一个字内(第12字符不是一个空格),我想移动我的光标“,直到它找到一个空间的回报串尽管超过12长字符。我怎样才能做到这一点?感谢

有帮助吗?

解决方案

是这样的:

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

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

也可以考虑内置PHP 换行

其他提示

可以使用strpos()

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

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

strpos();偏移将被$pieceLength,但返回位置仍然是来自干草堆的开始。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top