note 118726 added to function.count-chars

From: Date: Tue, 26 Jan 2016 17:29:46 +0000
Subject: note 118726 added to function.count-chars
Groups: php.notes 
Request: Send a blank email to php-notes+get-204773@lists.php.net to get a copy of this message
count_chars for multibyte supported. <?php function mb_count_chars ($string, $mode = 0) { $result = array_fill(0, 256, 0); for ($i = 0, $size = mb_strlen($string); $i < $size; $i++) { $char = mb_substr($string, $i, 1); if (strlen($char) > 1) { continue; } $code = ord($char); if ($code >= 0 && $code <= 255) { $result[$code]++; } } switch ($mode) { case 1: // same as 0 but only byte-values with a frequency greater than zero are listed. foreach ($result as $key => $value) { if ($value == 0) { unset($result[$key]); } } break; case 2: // same as 0 but only byte-values with a frequency equal to zero are listed. foreach ($result as $key => $value) { if ($value > 0) { unset($result[$key]); } } break; case 3: // a string containing all unique characters is returned. $buildString = ''; foreach ($result as $key => $value) { if ($value > 0) { $buildString .= chr($key); } } return $buildString; case 4: // a string containing all not used characters is returned. $buildString = ''; foreach ($result as $key => $value) { if ($value == 0) { $buildString .= chr($key); } } return $buildString; } // change key names... foreach ($result as $key => $value) { $result[chr($key)] = $value; unset($result[$key]); } return $result; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 153.222.225.86 ---- Manual Page -- http://php.net/manual/en/function.count-chars.php Edit -- https://master.php.net/note/edit/118726 Del: integrated -- https://master.php.net/note/delete/118726/integrated Del: useless -- https://master.php.net/note/delete/118726/useless Del: bad code -- https://master.php.net/note/delete/118726/bad+code Del: spam -- https://master.php.net/note/delete/118726/spam Del: non-english -- https://master.php.net/note/delete/118726/non-english Del: in docs -- https://master.php.net/note/delete/118726/in+docs Del: other reasons-- https://master.php.net/note/delete/118726 Reject -- https://master.php.net/note/reject/118726 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204773) next »