So i have a list of articles, and I have a page in which shows 4 articles at a time and then shortens the description of the article to 1000 characters and allows users to "read more", my problem is within each post there could be tags IE: <i>
or <b>
<img>
<center>
etc, how when truncating the text can I see if there are any open tags within the div or within the called upon text?
Here is how it looks for now
$sum = strip_tags($article, '<a><i><b><u><center><br><img><a><span><iframe>');
if (strlen($sum) > 1000) {
$sumCut = substr($sum, 0, 1000);
$sum = substr($sumCut, 0, strrpos($sumCut, ' ')).'... <div class="right"><a href="article-' .$record[nid]. '">Read More</a></div>';
}
echo $sum;
For example
If I have...
Quisque imperdiet imperdiet fringilla. Quisque sit amet nibh odio. Fusce sit amet massa vitae mi faucibus viverra.
The code fo that would be <i>Quisque imperdiet imperdiet fringilla. Quisque sit amet nibh odio. Fusce sit amet massa vitae mi faucibus viverra.</i>
but if I were to set my truncating number to say 10, it would leave that tag open and thus everything afterwords would be in italics