简体   繁体   English

PHP分页脚本

[英]PHP pagination script

$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. 我想做的是,如果第12个字符位于一个单词内(第12个字符不是空格),我想移动光标,直到找到一个空格,然后返回该子字符串,尽管事实上它的长度超过了12个字符。 how can i do that? 我怎样才能做到这一点? thanks 谢谢

You can use strpos() 您可以使用strpos()

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

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

something like this: 像这样的东西:

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

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

Also consider php builtin wordwrap 还考虑php内置的自动换行

Look at strpos() ; 看一下strpos() ; offset would be $pieceLength , but position returned is still from beginning of the haystack. offset将是$pieceLength ,但是返回的位置仍然是从$pieceLength开头开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM