приведение к нижнему регистру php

strtolower

(PHP 4, PHP 5, PHP 7, PHP 8)

strtolower — Преобразует строку в нижний регистр

Описание

Принадлежность того или иного символа к буквенным определяется с учётом текущей локали. Это означает, что, например, в используемой по умолчанию локали «C», символ Ä не будет преобразован.

Список параметров

Возвращаемые значения

Возвращает строку в нижнем регистре.

Примеры

Пример #1 Пример использования strtolower()

Примечания

Замечание: Эта функция безопасна для обработки данных в двоичной форме.

Смотрите также

User Contributed Notes 16 notes

strtolower(); doesn’t work for polish chars

for cyrillic and UTF 8 use mb_convert_case

//output is: австралия
?>

the function arraytolower will create duplicate entries since keys are case sensitive.

I prefer this method

Array
(
[test1] => asgafasdaad
[TEST2] => asddhshsdgb
[TeSt3] => asdasda@asdadadasdasdgh
)
Array
(
[test1] => asgafasdaad
[test2] => asddhshsdgb
[test3] => asdasda@asdadadasdasdgh
)

echo fullLower ( «Ã É Ò Õ ÚÙÛ» );

//results ã é ò õ úùû
//adapted from fullUpper on strtoupper manual
?>

When you’re not sure, how the current locale is set, you might find the following function useful. It’s strtolower for utf8-formatted text:

If you’re considering using the below unhtmlentities function from phpContrib, I would suggest this one as an alternative:

There’s a ucfirst «function» to make the first character uppercase, but there’s no «lcfirst» function to make the first character lowercase. Here’s my own code to accomplish this.

I found this particularly useful for generating XML nodes with the Reflection class.

Heres a small function I wrote to stop people from submitting data that is ALL IN CAPS SO THEY CAN GET MORE ATTENTION THAT THE REST OF THE USER SUBMITTED DATA on my website 🙂 If you can make it better, by all means do so. This function splits up words delimited by a space, and makes only the first letter of each word capitalized. You can easily modify it so it’s only the very first word of the string. I’ve also added some exceptions so you don’t make things like roman numerals look like «Iii» or «Xcmii» or something.

function RemoveShouting($string)
<
$lower_exceptions = array(
«to» => «1», «a» => «1», «the» => «1», «of» => «1»
);

$higher_exceptions = array(
«I» => «1», «II» => «1», «III» => «1», «IV» => «1»,
«V» => «1», «VI» => «1», «VII» => «1», «VIII» => «1»,
«XI» => «1», «X» => «1»
);

To do case insensitive comparisons in a database, strtolower() can be a quick and dirty solution:

$Sql = «SELECT * FROM tablename WHERE LOWER(column_name) = ‘».strtolower($my_var).»‘»;

the strtolower version to support most amount of languages including russian, french and so on:

To convert an entire array to lower, I prefer this method;

If you ever need to strtolower a string with href tags on it and doesn’t want to mess with the characters inside a tag, this is for you.

?>

this:
echo loweroutsidetags(‘aALalala ‘)

Источник

mb_convert_case

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

mb_convert_case — Производит смену регистра символов в строке

Описание

Список параметров

Строка ( string ) для преобразования.

Возвращаемые значения

Список изменений

Примеры

Пример #1 Пример использования mb_convert_case()

Пример #2 Пример использования mb_convert_case() с нелатинским UTF-8 текстом

Примечания

Дополнительную информацию о свойствах Юникода смотрите по ссылке» http://www.unicode.org/reports/tr21/.

Смотрите также

User Contributed Notes 9 notes

as the previouly posted version of this function doesn’t handle UTF-8 characters, I simply tried to replace ucfirst to mb_convert_case, but then any previous case foldings were lost while looping through delimiters.
So I decided to do an mb_convert_case on the input string (it also deals with words is uppercase wich may also be problematic when doing case-sensitive search), and do the rest of checking after that.

As with mb_convert_case, words are capitalized, I also added lowercase convertion for the exceptions, but, for the above mentioned reason, I left ucfirst unchanged.

Now it works fine for utf-8 strings as well, except for string delimiters followed by an UTF-8 character («Mcádám» is unchanged, while «mcdunno’s» is converted to «McDunno’s» and «ökrös-TÓTH éDUa» in also put in the correct form)

I use it for checking user input on names and addresses, so exceptions list contains some hungarian words too.

Источник

Функции для работы с многобайтовыми строками

Схемы многобайтного кодирования символов и их реализации достаточно сложны, и их описание находится за пределами этой документации. Более исчерпывающую информацию о кодировках и их устройстве можно почерпнуть из нижеприведённых источников.

    Материалы по Юникоду

    Информация о символах японской/корейской/китайской кодировок

    Содержание

    User Contributed Notes 35 notes

    Please note that all the discussion about mb_str_replace in the comments is pretty pointless. str_replace works just fine with multibyte strings:

    = ‘漢字はユニコード’ ;
    $needle = ‘は’ ;
    $replace = ‘Foo’ ;

    ?>

    The usual problem is that the string is evaluated as binary string, meaning PHP is not aware of encodings at all. Problems arise if you are getting a value «from outside» somewhere (database, POST request) and the encoding of the needle and the haystack is not the same. That typically means the source code is not saved in the same encoding as you are receiving «from outside». Therefore the binary representations don’t match and nothing happens.

    PHP can input and output Unicode, but a little different from what Microsoft means: when Microsoft says «Unicode», it unexplicitly means little-endian UTF-16 with BOM(FF FE = chr(255).chr(254)), whereas PHP’s «UTF-16» means big-endian with BOM. For this reason, PHP does not seem to be able to output Unicode CSV file for Microsoft Excel. Solving this problem is quite simple: just put BOM infront of UTF-16LE string.

    SOME multibyte encodings can safely be used in str_replace() and the like, others cannot. It’s not enough to ensure that all the strings involved use the same encoding: obviously they have to, but it’s not enough. It has to be the right sort of encoding.

    UTF-8 is one of the safe ones, because it was designed to be unambiguous about where each encoded character begins and ends in the string of bytes that makes up the encoded text. Some encodings are not safe: the last bytes of one character in a text followed by the first bytes of the next character may together make a valid character. str_replace() knows nothing about «characters», «character encodings» or «encoded text». It only knows about the string of bytes. To str_replace(), two adjacent characters with two-byte encodings just looks like a sequence of four bytes and it’s not going to know it shouldn’t try to match the middle two bytes.

    While real-world examples can be found of str_replace() mangling text, it can be illustrated by using the HTML-ENTITIES encoding. It’s not one of the safe ones. All of the strings being passed to str_replace() are valid HTML-ENTITIES-encoded text so the «all inputs use the same encoding» rule is satisfied.

    The text is «x = ‘x ;
    mb_internal_encoding ( ‘HTML-ENTITIES’ );

    ?>

    Even though neither ‘l’ nor ‘;’ appear in the text «x y» and in the other it broke the encoding completely.

    One more reason to use UTF-8 if you can, I guess.

    Yet another single-line mb_trim() function

    PHP5 has no mb_trim(), so here’s one I made. It work just as trim(), but with the added bonus of PCRE character classes (including, of course, all the useful Unicode ones such as \pZ).

    Источник

    strtoupper

    (PHP 4, PHP 5, PHP 7, PHP 8)

    strtoupper — Преобразует строку в верхний регистр

    Описание

    Принадлежность того или иного символа к буквенным определяется с учётом текущей локали. Это означает, что, например, в используемой по умолчанию локали «C», символ ä не будет преобразован.

    Список параметров

    Возвращаемые значения

    Возвращает строку в верхнем регистре.

    Примеры

    Пример #1 Пример использования strtoupper()

    Примечания

    Замечание: Эта функция безопасна для обработки данных в двоичной форме.

    Смотрите также

    User Contributed Notes 16 notes

    One might think that setting the correct locale would do the trick with for example german umlauts, but this is not the case. You have to use mb_strtoupper() instead:

    Here is how to make the character in upper case, except HTML-entities:

    If you only need to extend the conversion by the characters of a certain language, it’s possible to control this using an environment variable to change the locale:

    When using UTF-8 and need to convert to uppercase with
    special characters like the german ä,ö,ü (didn’t test for french,polish,russian but think it should work, too) try this:

    If you can’t find an appropriate locale setting, check your system configuration (locales are a system-wide setting, PHP gets them from the OS). On Windows, locales can be set from the Control Panel; on Linux it depends on your distribution. You can try «sudo dpkg-reconfigure locales» on Debian-based distros, or configure them manually. On Ubuntu Dapper, I had to copy entries over from /usr/share/i18n/SUPPORTED to /var/lib/locales/supported.d/local, then do the dpkg-reconfigure.

    After you’re done, restart the web server.

    That said, there are special cases where you want to do the conversion manually. In German, for example, the letter ‘ß’ (szlig) only exists as a lower-case character, and so doesn’t get converted by strtoupper. The convential way to express a ‘ß’ in an uppercase string is «SS». This function will take care of this exception (for Latin1 and most of Latin9, at least):

    Источник

    mb_strtolower

    mb_strtolower — Приведение строки к нижнему регистру

    Описание

    Список параметров

    Параметр encoding представляет собой символьную кодировку. Если он опущен, вместо него будет использовано значение внутренней кодировки.

    Возвращаемые значения

    Юникод

    За дополнительной информацией о свойствах Юникода обращайтесь в » http://www.unicode.org/unicode/reports/tr21/.

    Примеры

    Пример #1 Пример использования mb_strtolower()

    Пример #2 Пример использовани mb_strtolower() с нелатинскими буквами

    Смотрите также

    Коментарии

    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.

    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:

    = «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 );

    // MySQL lower()
    $timeSQL = microtime ( true );

    // Result on my notebook:
    // mb: 11.50642 sek.
    // sql: 5.44143 sek.

    It’s also apply to
    Call to undefined function mb_eregi() / mb_strtolower()

    Please, note that when using with UTF-8 mb_strtolower will only convert upper case characters to lower case which are marked with the Unicode property «Upper case letter» («Lu»). However, there are also letters such as «Letter numbers» (Unicode property «Nl») that also have lower case and upper case variants. These characters will not be converted be mb_strtolower!

    Big internet-companies (like Google) do match both variants as semantically equal (since the representations only differ in case).

    Since I was not finding any proper solution in the internet on how to map all UTF8-strings to their lowercase counterpart in PHP, I offer the following hard-coded extended mb_strtolower function for UTF-8 strings:

    There is not a one-to-one correspondence between upper and lower case letters.

    Turkish is a good example of this. In Turkish, the letter I/i has a dotted-upper-case form (İ) and a dotless-lower-case form (ı).

    This means that you cannot correctly convert between upper-case and lower-case without also knowing the locale of the data.

    Since the function does not let you specify a locale, you should only use this function for text written in languages that follow the same orthography as English.

    Although it does handle some digraphs, such as the Dutch ij (ij), it does not handle others, such as the Polish dz (ʣ).

    Maybe it help someone.
    Make up case with first char, low case for other.

    Источник

    Добавить комментарий

    Ваш адрес email не будет опубликован. Обязательные поля помечены *