note 120332 added to ref.mbstring

From: Date: Wed, 14 Dec 2016 13:36:48 +0000
Subject: note 120332 added to ref.mbstring
Groups: php.notes 
Request: Send a blank email to php-notes+get-208590@lists.php.net to get a copy of this message
The suggestion from "mt at mediamedics dot nl" is not that bad like the down votes indicate. There is only one small bug which can be easily fixed to make it work. The head of the "for" need to be modified by replacing $i + $split_length by $i += $split_length. Here is the full working code, with additional check to verify that the method doesn't exists already: <?php if ( !function_exists('mb_str_split') ) { function mb_str_split($string, $split_length = 1) { mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); $split_length = ($split_length <= 0) ? 1 : $split_length; $mb_strlen = mb_strlen($string, 'utf-8'); $array = array(); for($i = 0; $i < $mb_strlen; $i += $split_length) { $array[] = mb_substr($string, $i, $split_length); } return $array; } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 213.61.241.82 ---- Manual Page -- http://php.net/manual/en/ref.mbstring.php Edit -- https://master.php.net/note/edit/120332 Del: integrated -- https://master.php.net/note/delete/120332/integrated Del: useless -- https://master.php.net/note/delete/120332/useless Del: bad code -- https://master.php.net/note/delete/120332/bad+code Del: spam -- https://master.php.net/note/delete/120332/spam Del: non-english -- https://master.php.net/note/delete/120332/non-english Del: in docs -- https://master.php.net/note/delete/120332/in+docs Del: other reasons-- https://master.php.net/note/delete/120332 Reject -- https://master.php.net/note/reject/120332 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#208590) next »