note 112070 added to function.mb-substr

From: Date: Mon, 29 Apr 2013 15:51:06 +0000
Subject: note 112070 added to function.mb-substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-194653@lists.php.net to get a copy of this message
quick and dirty loop through multibyte string <?php function get_character_classes($string, $encoding = "UTF-8") { $current_encoding = mb_internal_encoding(); mb_internal_encoding($encoding); $has = array(); $stringlength = mb_strlen($string, $encoding); for ($i=0; $i < $stringlength; $i++) { $c = mb_substr($string, $i, 1); if (($c >= "0") && ($c <= "9")) { $has['numeric'] = "numeric"; } else if (($c >= "a") && ($c <= "z")) { $has['alpha'] = "alpha"; $has['alphalower'] = 'alphalower'; } else if (($c >= "A") && ($c <= "Z")) { $has['alpha'] = "alpha"; $has['alphaupper'] = "alphaupper"; } else if (($c == "$") || ($c == "£")) { $has['currency'] = "currency"; } else if (($c == ".") && ($has['decimal'])) { $has['decimals'] = "decimals"; } else if ($c == ".") { $has['decimal'] = "decimal"; } else if ($c == ",") { $has['comma'] = "comma"; } else if ($c == "-") { $has['dash'] = "dash"; } else if ($c == " ") { $has['space'] = "space"; } else if ($c == "/") { $has['slash'] = "slash"; } else if ($c == ":") { $has['colon'] = "colon"; } else if (($c >= " ") && ($c <= "~")) { $has['ascii'] = "ascii"; } else { $has['binary'] = "binary"; } } mb_internal_encoding($current_encoding); return $has; } $string = "1234asdfA£^_{}|}~žščř"; echo print_r(get_character_classes($string), true); ?> Array ( [numeric] => numeric [alpha] => alpha [alphalower] => alphalower [alphaupper] => alphaupper [currency] => currency [ascii] => ascii [binary] => binary ) ---- Server IP: 69.147.83.199 Probable Submitter: 82.20.75.197 ---- Manual Page -- http://php.net/manual/en/function.mb-substr.php Edit -- https://master.php.net/note/edit/112070 Del: integrated -- https://master.php.net/note/delete/112070/integrated Del: useless -- https://master.php.net/note/delete/112070/useless Del: bad code -- https://master.php.net/note/delete/112070/bad+code Del: spam -- https://master.php.net/note/delete/112070/spam Del: non-english -- https://master.php.net/note/delete/112070/non-english Del: in docs -- https://master.php.net/note/delete/112070/in+docs Del: other reasons-- https://master.php.net/note/delete/112070 Reject -- https://master.php.net/note/reject/112070 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194653) next »