2009-10-30 67 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,但返回的位置仍然是乾草堆的開始。