note 125015 added to intlchar.tolower
| From: | Patanjali@php.net | Date: | Fri, 15 May 2020 23:00:04 +0000 |
| Subject: | note 125015 added to intlchar.tolower | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214638@lists.php.net to get a copy of this message | ||
The other function I wrote to replace mb_strtolower may not work properly, as it erroneously equated
graphemes with codepoints.
tolower, like many IntlChar methods, works specifically on codepoints, so requires a codepoint
iterator to isolate each.
Also, because in tolower, if there is no lowercase version of the codepoint, the supplied one is
returned, so there is no need to specially test for alphabetic codepoints before conversion.
<?php
function u_tolower($text=''){
// if blank, return blank (don't waste CPU cycles)
if($text==''){return'';}
// create the codepoint break iterator to identify the start of each codepoint
$iterator=IntlBreakIterator::createCodePointInstance();
// load the text
$iterator->setText($text);
// using a parts iterator to extract each codepoint itself, convert and append it to the new string
$newtext='';
foreach($iterator->getPartsIterator() as $codepoint){$newtext.=IntlChar::tolower($codepoint);}
// return converted text
return $newtext;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 101.0.109.162 (proxied: 61.68.126.217)
----
Manual Page -- http://php.net/manual/en/intlchar.tolower.php
Edit -- https://master.php.net/note/edit/125015
Del: integrated -- https://master.php.net/note/delete/125015/integrated
Del: useless -- https://master.php.net/note/delete/125015/useless
Del: bad code -- https://master.php.net/note/delete/125015/bad+code
Del: spam -- https://master.php.net/note/delete/125015/spam
Del: non-english -- https://master.php.net/note/delete/125015/non-english
Del: in docs -- https://master.php.net/note/delete/125015/in+docs
Del: other reasons-- https://master.php.net/note/delete/125015
Reject -- https://master.php.net/note/reject/125015
Search -- https://master.php.net/manage/user-notes.php