$char_number) { $text = substr($text, 0, $char_number); $text = substr($text,0,strrpos($text," ")); $punctuation = ".!?:;,-"; //punctuation you want removed $text = (strspn(strrev($text), $punctuation) != 0) ? substr($text, 0, -strspn(strrev($text), $punctuation)) : $text; $text = $text.$etc; } $text = htmlentities($text, ENT_QUOTES); return $text; }