note 14396 deleted from function.wordwrap by jimw

From: Date: Fri, 14 Dec 2001 20:39:36 +0000
Subject: note 14396 deleted from function.wordwrap by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22775@lists.php.net to get a copy of this message
This is a 'Multi-byte' safe wordwrap. Everything is like original wordwrap, except never-destroy multi-byte language. As the case may be, this is faster or slower than original wordwrap. Good luck and help youself. ---------------------------------------------- function mb_wordwrap($str) { $width = 75; $break = "\n"; switch(func_num_args()) { case 4 : $cut = func_get_arg(3); case 3 : $break = func_get_arg(2); case 2 : $width = func_get_arg(1); } $str_len = strlen($str); for($start = 0; $start < $str_len; ) { $width_conv = $width; $end_chr = ord($str[$start + $width - 1]); if(!$cut && $end_chr != 32) $width_conv += strpos(substr($str, $start + $width), " ") + 1; elseif($cut && $end_chr > 127) // ÇѱÛÀÏ °æ¿ì 1Byte ´ú ÀÚ¸§ { for($end = $start + $width - 1, $h = 0; $end >= $start; $end--) if(ord($str[$end]) > 127) $h++; else break; if($h%2!=0) $width_conv = $width - 1; } $str_line = substr($str, $start, $width_conv); $start += $width_conv; if($start < $str_len) $str_line .= $break; $str_conv .= $str_line; } return $str_conv; }

« previous php.notes (#22775) next »