|
mb_strtolower
Make a string lowercase
(PHP 4 >= 4.3.0, PHP 5)
Example 1406. mb_strtolower() example<?php Code Examples / Notes » mb_strtolowerphilipp h
Note that mb_strtolower() is very SLOW, if you have a database connection, you may want to use it to convert your strings to lower case. Even latin1/9 (iso-8859-1/15) and other encodings are possible. Have a look at my simple benchmark: <?php $text = "Lörem ipÃüm dölör Ãit ämet, cönÃectetüer ädipiÃcing elit. Sed ligülä. PräeÃent jüÃtö tellüÃ, grävidä eü, tempüà ä, mättià nön, örci. Näm qüià lörem. Näm äliqüet elit Ãed elit. PhäÃellüà venenätià jüÃtö eget enim. Dönec niÃl. Pröin mättià venenätià jüÃtö. Sed äliqüäm pörtä örci. Cräà elit niÃl, cönvällià qüiÃ, tincidünt ät, vehicülä äccümÃän, ödiö. Sed möleÃtie. Etiäm möllià feügiät elit. VeÃtibülüm änte ipÃüm primià in fäücibüà örci lüctüà et ültriceà pöÃüere cübiliä Cüräe; Mäecenäà nön nüllä."; // mb_strtolower() $timeMB = microtime(true); for($i=0;$i<30000;$i++) $lower = mb_strtolower("$text/no-cache-$i"); $timeMB = microtime(true) - $timeMB; // MySQL lower() $timeSQL = microtime(true); mysql_query("set names latin1"); for($i=0;$i<30000;$i++) { $r = mysql_fetch_row(mysql_query("select lower('$text/no-cache-$i')")); $lower = $r[0]; } $timeSQL = microtime(true) - $timeSQL; echo "mb: ".sprintf("%.5f",$timeMB)." sek.<br />"; echo "sql: ".sprintf("%.5f",$timeSQL)." sek.<br />"; // Result on my notebook: // mb: 11.50642 sek. // sql: 5.44143 sek. ?> btherl
If you use this function on a unicode string without telling PHP that it is unicode, then you will corrupt your string. In particular, the uppercase 'A' with tilde, common in 2-byte UTF-8 characters, is converted to lowercase 'a' with tilde. This can be handled correctly by: $str = mb_strtolower($str, mb_detect_encoding($str)); Or if you know your data is UTF-8, just use the string "UTF-8" as the second argument. You should check also that mb_detect_encoding() is checking the encodings you want it to check, and is detecting the correct encodings. |
Change Languagemb_check_encoding mb_convert_case mb_convert_encoding mb_convert_kana mb_convert_variables mb_decode_mimeheader mb_decode_numericentity mb_detect_encoding mb_detect_order mb_encode_mimeheader mb_encode_numericentity mb_ereg_match mb_ereg_replace mb_ereg_search_getpos mb_ereg_search_getregs mb_ereg_search_init mb_ereg_search_pos mb_ereg_search_regs mb_ereg_search_setpos mb_ereg_search mb_ereg mb_eregi_replace mb_eregi mb_get_info mb_http_input mb_http_output mb_internal_encoding mb_language mb_output_handler mb_parse_str mb_preferred_mime_name mb_regex_encoding mb_regex_set_options mb_send_mail mb_split mb_strcut mb_strimwidth mb_stripos mb_stristr mb_strlen mb_strpos mb_strrchr mb_strrichr mb_strripos mb_strrpos mb_strstr mb_strtolower mb_strtoupper mb_strwidth mb_substitute_character mb_substr_count mb_substr |