note 99081 added to function.mb-convert-case
| From: | cataphract@php.net | Date: | Mon, 26 Jul 2010 18:06:15 +0000 |
| Subject: | note 99081 added to function.mb-convert-case | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171145@lists.php.net to get a copy of this message | ||
This is a variation of mb_convert_case that works only for UTF-8 strings and that will not convert
to lowercase anything.
This avoids turning "AAA aaa" into "Aaa Aaa"; it maps "AAA aaa" into
""AAA Aaa" instead.
<?php
function mb_convert_case_utf8_variation($s) {
$arr = preg_split("//u", $s, -1, PREG_SPLIT_NO_EMPTY);
$result = "";
$mode = false;
foreach ($arr as $char) {
$res = preg_match(
'/\\p{Mn}|\\p{Me}|\\p{Cf}|\\p{Lm}|\\p{Sk}|\\p{Lu}|\\p{Ll}|'.
'\\p{Lt}|\\p{Sk}|\\p{Cs}/u', $char) == 1;
if ($mode) {
if (!$res)
$mode = false;
}
elseif ($res) {
$mode = true;
$char = mb_convert_case($char, MB_CASE_TITLE, "UTF-8");
}
$result .= $char;
}
return $result;
}
?>
See also http://stackoverflow.com/questions/3296086
----
Server IP: 194.8.30.16
Probable Submitter: 93.108.152.52
----
Manual Page -- http://www.php.net/manual/en/function.mb-convert-case.php
Edit -- https://master.php.net/note/edit/99081
Del: integrated -- https://master.php.net/note/delete/99081/integrated
Del: useless -- https://master.php.net/note/delete/99081/useless
Del: bad code -- https://master.php.net/note/delete/99081/bad+code
Del: spam -- https://master.php.net/note/delete/99081/spam
Del: non-english -- https://master.php.net/note/delete/99081/non-english
Del: in docs -- https://master.php.net/note/delete/99081/in+docs
Del: other reasons-- https://master.php.net/note/delete/99081
Reject -- https://master.php.net/note/reject/99081
Search -- https://master.php.net/manage/user-notes.php