0

Ok, so let me try to explain what I'm trying to do here. I have a PHP variable called $pageContent which basically contains the whole HTML for a detail page in my blog. Now every page contains an ul at the top of it that is transformed in a carousel when you open the detail page, the number of li can vary between typically 2 - 6. However, I also have an overview page which contains a list with short descriptions of each page. I use PHP's substr() to shorten what is inside $pageContent. How can I shorten my string without taking the part from <ul> to </ul> into account? The ul is set to display: none; with css, but when shortening the characters of the ul are still taken into account. Does anyone have a solution for me?

A sample of the HTML that could be inside $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>

My output should look something like:

<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>

And not like:

<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>
  • I added the extra info ;) –  Oct 08 '13 at 10:01
  • This can be easily achieved with [DOM parsing](http://stackoverflow.com/a/3577662/67332) like [this example](http://stackoverflow.com/a/9549426/67332). – Glavić Oct 08 '13 at 10:04