note 32886 added to function.wordwrap

From: Date: Tue, 10 Jun 2003 04:15:01 +0000
Subject: note 32886 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-50073@lists.php.net to get a copy of this message
Here is another function for soft-hypens. It could also be used with spaces which is actually probably a reasonable idea since ­ is not universally supported (ie netscape through 6.2 doesn't handle it). /** * soft_hypen() inserts soft hyphens (or user defined) in words that exceed certain length. * * @param $text Text to hyphenate. * @param $max Max word size. * @param $char Hyphenate character. Defaults to HTML soft hyphen ­. * @return The text with inserted soft hyphens. **/ function soft_hyphen($text, $max, $char = "­") { $words = explode(' ', $text); foreach($words as $key => $word) { $length = strlen($word); if($length > $max) $word = chunk_split($word, floor($length/ceil($length/$max)), $char); $words[$key] = $word; } return implode(' ', $words); } ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32886 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32886&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32886&report=yes

« previous php.notes (#50073) next »