note 32886 modified in function.wordwrap by aidan

From: Date: Mon, 19 Jul 2004 23:26:34 +0000
Subject: note 32886 modified in function.wordwrap by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73652@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). <?php /** * 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); } ?> --was-- Here is another function for soft-hypens. It could also be used with spaces which is actually probably a reasonable idea since &shy; 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 &shy;. * @return The text with inserted soft hyphens. **/ function soft_hyphen($text, $max, $char = "&shy;") { $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); } http://php.net/manual/en/function.wordwrap.php

« previous php.notes (#73652) next »