0

好的,让我试着解释一下我在这里想要做什么。我有一个名为的 PHP 变量$pageContent,它基本上包含我博客中详细信息页面的整个 HTML。现在每个页面ul的顶部都包含一个,当您打开详细信息页面时,它会在轮播中转换,数量li通常在 2 到 6 之间变化。但是,我还有一个概览页面,其中包含一个带有简短描述的列表每一页。我使用 PHPsubstr()来缩短里面的内容$pageContent<ul>如何在不考虑 from to部分的情况下缩短我的字符串</ul>ul是用css设置的,display: none;但是在缩短字符的时候ul还是会考虑到的。有人对我有解决方案吗?

可能位于内部的 HTML 示例$pageContent

<ul>
    <li>This text shouldn't be shown in the shortened version.</li>
    <li>This text shouldn't be shown in the shortened version.</li>
    <li>This text shouldn't be shown in the shortened version.</li>
</ul>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in lorem venenatis, pellentesque dolor tempor, malesuada mi. Nullam non sapien quis augue aliquet rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque adipiscing ligula vel lacinia cursus. Vestibulum eu nunc id dui bibendum hendrerit. Vestibulum et augue eu massa tincidunt fringilla sit amet lobortis lorem. Morbi sodales lorem at rutrum posuere. Suspendisse potenti. Suspendisse ornare metus id feugiat tincidunt. Cras et libero in metus bibendum scelerisque. Sed consectetur, arcu id auctor sagittis, magna turpis scelerisque nibh, et vulputate sapien eros quis augue. Nunc nec eros libero.</p>

我的输出应该类似于:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in lorem venenatis, pellentesque dolor tempor, malesuada mi. Nullam non sapien quis augue aliquet rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque adipiscing ligula vel lacinia curs ...</p>

而且不喜欢:

<ul>
    <li>This text shouldn't be shown in the shortened version.</li>
    <li>This text shouldn't be shown in the shortened version.</li>
    <li>This text shouldn't be shown in the shortened version.</li>
</ul>

<p>Lorem ipsu ...</p>
4

0 回答 0