我有一个页面,它有多个H1标题,后面跟着文本等等。示例:
<h1>Title 1</h1>Some text here
<h1>Title 2</h1>Some more text here
<h1>Title 3</h1>Even more text here等
我想要做的是创建一个元素数组,也就是使用上面$output变量中的分隔符<h1>ANY TEXT</h1>分解HTML。
最终目的是计算结束</h1>和下一个开始<h1>之间的文本字符串,如果字符串超过200个字符,则使用display:none将其隐藏在<span>中,以便用户可以按"Show all“取消隐藏。
我该怎么做呢?
发布于 2010-08-30 21:28:28
在将页面发送到客户端之前,您可以使用SimplePHPDom来完成此操作:
ob_start();
// build page here
$html = ob_get_clean();
$dom = str_get_html($html);
$headings = $dom->find('h1');
foreach($headings as $h1) {
// process node to add CSS to hide node and change text to 'show more'
}这也可以通过jQuery/MooTools在客户端完成,使用基本相同的过程(不包括缓冲捕获内容)。
https://stackoverflow.com/questions/3600662
复制相似问题