note 94452 deleted from function.wordwrap by googleguy

From: Date: Tue, 22 Oct 2013 11:18:14 +0000
Subject: note 94452 deleted from function.wordwrap by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197095@lists.php.net to get a copy of this message
Note Submitter: andrnag at yandex dot ru ---- This is a really working multibite wordwrap function. Teted on utf-8 English and Russian strings. It's a compilation on other functions represented here. <?php function utf8_wordwrap($str, $width = 75, $break = "\n") // wordwrap() with utf-8 support { $str = preg_split('/([\x20\r\n\t]++|\xc2\xa0)/sSX', $str, -1, PREG_SPLIT_NO_EMPTY); $len = 0; foreach ($str as $val) { $val .= ' '; $tmp = mb_strlen($val, 'utf-8'); $len += $tmp; if ($len >= $width) { $return .= $break . $val; $len = $tmp; } else $return .= $val; } return $return; } ?>

« previous php.notes (#197095) next »