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

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

我想要做的是,如果第 12 个字符在一个单词内(第 12 个字符不是空格),我想移动我的光标,直到它找到一个空格并返回该子字符串,尽管它的长度超过 12 个字符。我怎样才能做到这一点?谢谢

4

3 回答 3

4

您可以使用 strpos()

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

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

于 2009-10-30T21:29:57.120 回答
2

像这样的东西:

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

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

还要考虑 php 内置wordwrap

于 2009-10-30T21:27:44.007 回答
0

看看strpos();偏移量是$pieceLength,但返回的位置仍然是从大海捞针的开始。

于 2009-10-30T21:28:50.757 回答