jpopuk Posted May 2, 2014 Share Posted May 2, 2014 Hi, I am working on a project that I thought would be simple. Issue I am having is I need the content to display in HTML format in a post, which I have done. But I also need to limit the characters, and then a read more link will appear. This is the code I use to view the content which works fine: <?php echo check_output($post['content'], true, false, false); ?> This is how I am doing it though so it only shows so many characters: <?php $mylink = get_url('/blog/', $post['category_id'], $post['post_id'], $post['title']); echo strlen($post['content']) > 250 ? substr($post['content'], 0, 250) . '...<p align="right"><strong><a href="'. $mylink .'">read more</a></strong></p>' : $post['content']; ?> Issue I am having is the content is being displayed as text so it is showing <p> tags etc. If anybody could assist on merging the 2 so the content displayed shows HTML would be very much appreciated. This is the check_output fuction: function check_output($output, $allow_html = false) { if ($allow_html == true) { $output = html_entity_decode($output, ENT_QUOTES); } return $output; } Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 2, 2014 Share Posted May 2, 2014 (edited) Why are you passing four parameters to the check_output(0 function which only accepts two? The problem that you are going to have is that if you are going to limit the comments to a certain length, you will end up with some invalid HTML code because some opening HTML tags may come after the point where you are going to limit the length. This is not a trivial problem to solve. I'd suggest some google searching to find a solution that someone has already built. This seems to include some good resources: https://www.google.com/#q=php+truncate+text+retain+HTML Edited May 2, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
jpopuk Posted May 11, 2014 Author Share Posted May 11, 2014 Thanks for reply. What you said made good sense with regards to only allowing a certain length as HTML would be invalid. I did a simple solution and put the HTML in a div with overflow set to scroll. - Not the most ideal way but it looks fine! Again thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.