Shrink the string to a specific number of characters, ignoring HTML
I am using Codeigniter's character_limiter () function to trim a string to a specific number of characters. I am using this to create excerpt from extracts.
The problem is that the string contains HTML tags, so these characters are counted but not visible. Also, it can cut a line in the middle of the tag and mess up the page formatting.
For example, if I have the following:
This is some text with a <a href="http://google.com">a link</a>
If I limit it to 54 characters, it gets disabled after the a in the "link", and there is no end tag, and it turns everything after it into anchor text.
How can I prevent this? Should I just strip out all HTML tags entirely before limiting characters?
+3
source to share
2 answers
$this->load->helper('text');
echo word_limiter(strip_tags($description),40);
What I do for the meta description, try http://caverne.fr
+1
source to share