Hi folks,
I'm building a page that displays content from a database. I'm using CKEditor to add content to the database which includes basic html tags such as <p>, <img>, etc
On the page however, I want to shorten an article and have a more link below it.
An example of what I have:
//$content holds content data from my SQL
<?php
$stripped_content = stripslashes($content);
$final_content = preg_replace("/<img[^>]+\>/i", "", $stripped_content)
?>
<div>
<?php echo substr($final_content, 0, 330) . ' ... </p>'; ?>
<p style="text-align: right;">
<a href="article.php?id=<?php echo $a_id; ?>">more</a> »
</p>
</div>
After various tests where I'm changing the length of the output, some results show broken html tags. Below example using Lorem Ipsum shows a broken closed </p> tag
Praesent non felis.< ...
Is there a way around this? Also, if anyone has tips on how I can manipulate my strings instead of using multiple variables and lines of code.
Thanks in advance