PHP分页脚本

发布于 2024-08-09 17:11:02 字数 290 浏览 7 评论 0原文

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

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

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

$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. how can i do that? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对你再特殊 2024-08-16 17:11:02

您可以使用 strpos()

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

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

You can use strpos()

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

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

卸妝后依然美 2024-08-16 17:11:02

像这样的东西:

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

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

还要考虑 php 内置 wordwrap

something like this:

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

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

Also consider php builtin wordwrap

铃予 2024-08-16 17:11:02

看看 strpos();偏移量将为$pieceLength,但返回的位置仍然是从干草堆的开头开始。

Look at strpos(); offset would be $pieceLength, but position returned is still from beginning of the haystack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文