RE: [PHP] Substr and HTML tags - Problem...

From: Date: Mon, 25 Feb 2002 11:56:30 +0000
Subject: RE: [PHP] Substr and HTML tags - Problem...
Groups: php.general 
Request: Send a blank email to php-general+get-86069@lists.php.net to get a copy of this message
> Personally when I'm doing teasers I strip all HTML from the content > before using substr: > > $teaser = strip_tags($content); > $teaser = substr($teaser, 0, 100); > $teaser .= '...'; // Nice touch to have a '...' on the end :) > You don't have a handy way to check that your substr() doesn't cut off half-way through a word, do you? I'm up against this issue myself at the moment and it's a PITA to sort out - I keep getting things like "Fnord fnord fnord fnord fnord fno", where the last "fnord" is missing its "rd". It's bound to be a case of stepping back through the string until a space is encountered, and then keeping everything to the left of that, but I haven't worked out an elegant way to do it yet :-) Cheers Jon

« previous php.general (#86069) next »