Page 1 of 1

Problem with tags when integrating messages on my website.

Posted: Tue Jan 16, 2018 8:03 pm
by askafreedom
Hello world !!!
I have integrated the forum on my website, all works well.
But I use a function to truncate the message and if a tag (<b> <em> etc..) is opened before the function truncates the message, it stays open.
How to close automatically the opened tags?

here is a picture : Image

and the function to trunc the message :

Code: Select all

function tronquer_texte( $texte, $nbchar ) {
		return (strlen($texte) > $nbchar ? substr(substr($texte,0,$nbchar),0,
		strrpos(substr($texte,0,$nbchar)," "))." (...)" : $texte);
with the call function :

Code: Select all

					$text = preg_replace($patterns, $replace, $row[9]);
					$text = str_replace($amodif, $modif, $text);
					$text = nl2br($text);
                   			 echo tronquer_texte($text, 300);
thank you for your attention! :)
Cya !

EDIT : I have found a "temp solution" by replacing a part of the function (strrpos(substr($texte,0,$nbchar)," "))."</b></i></u> (...)" : $texte);)