July 30, 201115 yr Yea i have a custom blog i've been building which is here http://www.submitbannerusa.com/4Coding, the prob is i made where it will add a read More link incase each post go over 2500 characters, but sometimes it will cut off the closing tag of some of my BBcode which as u may guess makes everything below that broken tag bold or whatever, how would u fix this? the code im using for the readmore link is if(strlen($content) > 2500 && !$pid){ /** *If the content is greater then 2500 chars add the read-more link, * and cut the content down to 2500 chars * this cuts down on loading times for the main page * due to long post displaying **/ $content = substr($content,0,2500)."[...] <span class='readmore'><a href='./index.php?post=".$post['id']."'>Read More</a></span>"; } Edited July 30, 201115 yr by webdesigner93
July 30, 201115 yr Here's a link to a similar problem - http://stackoverflow.com/questions/1193500/php-truncate-html-ignoring-tags Shouldn't be too hard to adapt the solution from HTML to BBCODE.
August 1, 201115 yr After you substr the string, make a function that will look for the last BBCODE appearence. If it 's an opening BBCODE, add the equivalent closing one to the end. Since BBCODEs are not that many, it 's easily doable, maybe a bit boring but... Or you could get fancy, write a full fledged BBCODE parser, tokenize everything and manage it like that. But that would be like building a tank to go to the grocery store for shopping, so I 'd stick with the first solution.
Create an account or sign in to comment