note 27634 added to function.strrpos

From: Date: Fri, 13 Dec 2002 16:39:21 +0000
Subject: note 27634 added to function.strrpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-40867@lists.php.net to get a copy of this message
Maybe I'm the only one who's bothered by it, but it really bugs me when the last line in a paragraph is a single word. Here's an example to explain what I don't like: The quick brown fox jumps over the lazy dog. So that's why I wrote this function. In any paragraph that contains more than 1 space (i.e., more than two words), it will replace the last space with ' '. function no_orphans($TheParagraph) { if (substr_count($TheParagraph," ") > 1) { $lastspace = strrpos($TheParagraph," "); $TheParagraph = substr_replace($TheParagraph," ",$lastspace,1); } return $TheParagraph; } So, it would change "The quick brown fox jumps over the lazy dog." to "The quick brown fox jumps over the lazy dog." That way, the last two words will always stay together. -- http://www.php.net/manual/en/function.strrpos.php http://master.php.net/manage/user-notes.php?action=edit+27634 http://master.php.net/manage/user-notes.php?action=delete+27634 http://master.php.net/manage/user-notes.php?action=reject+27634

« previous php.notes (#40867) next »