2009-10-30 70 views
0
$string = "This is my page content. This text will be paginated."; 
$pageNo = "0"; 
$pieceLength = "12"; 

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

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

回答

2

是这样的:

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

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

也可以考虑PHP内置wordwrap

0

strpos();抵消将是$pieceLength,但返回的位置仍然是干草堆的开始。