I have a latest news section that lists the latest 10 news entries. I want to show a brief description of each news content then when the users clicks a Read More link it will show the entire news article.
The way I have it set up is the News content is in a varialbe ($content). This variable contains simple HTML, like bold, italics, underline, etc...
Right now I am using this code to display a brief description of the news
if (strlen($content) > 260) {
$content = trim(substr($content, 0, 260))."...";
}
This works great but I run into a problem when the 260th character is in the middle of a html tag. Casing something like this
News blah blah blah <b...
This messes up the rest of the code on the page since the tag is not closed. Is there a way I can check if the 260th character is a tag and fix this problem?