note 32886 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:37:24 +0000
Subject: note 32886 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155149@lists.php.net to get a copy of this message
Note Submitter: mzajonc at pomona dot edu ---- 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); } ?>

« previous php.notes (#155149) next »