【发布时间】:2019-08-16 10:44:24
【问题描述】:
例如,我从数据库中获取段落作为数组
<?php $data = [
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
"It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham."
];?>
我正在使用 css 和 html 作为报纸将段落打印到列中,并且页面中没有滚动,如果有额外的文本,它应该在第二页中。
所以例如 this 应该被渲染到 this 中
<div id="page-1">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div id="page-2">
<p>de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
</div>
我遇到的问题是我不知道如何知道何时拆分到第二页,我试图计算单词或段落,但我认为这不是一个好的解决方案。
请帮忙
【问题讨论】:
-
如果每个数组值都被视为像您的示例一样的列,我可能会
array_chunk()拆分值为2,然后循环块。 -
您不能使用 PHP 执行此操作,因为 PHP 在服务器上运行,并且不知道一页可以容纳多少信息(我假设这取决于客户端浏览器的大小等等? )