Converts characters in a string to lowercase.
Syntax:
String strtolower (string str);
Converts a string to lowercase. Returns the translation result.
It should be noted that if the locale is incorrectly configured, the function will produce, to put it mildly, strange results when working with Cyrillic letters.
$ str = "HeLLo World"; $ str = strtolower ($ str); echo $ str; // prints hello world
strtoupper
Converts the specified string to uppercase.
Syntax:
String strtoupper (string str);
Converts a string to uppercase. Returns the result of the transformation. This function works well with English letters, but it can be weird with Russian letters.
$ str = "Hello World"; $ str = strtoupper ($ str); echo $ str; // prints HELLO WORLD
ucfirst
Converts the first character of a string to uppercase.
Syntax:
String ucfirst (string str);
Returns a string whose first character is uppercase.
$ str = "hello world"; $ str = ucfirst ($ str); echo $ str; // prints Hello world
ucwords
Converts the first character of each word in a string to uppercase.
Syntax:
String ucwords (string str);
Returns a string that capitalizes the first character of each word in the string.
A word here means a section of a line preceded by a whitespace character: space, line feed, page feed, carriage return, horizontal and vertical tabs.
Cyrillic characters may not be converted correctly.
$ str = "hello world"; $ str = ucfirst ($ str); echo $ str; // prints Hello World
PHP is good for the variety of native language features. However, in some cases it is necessary to add the missing functionality. This is especially noticeable when working with functions for converting strings and various encodings.
For example, ucfirst is a function that converts the first character of a string to uppercase. It would seem that there should be no problems, but when working with Cyrillic, such a transformation does not occur. This also applies to the ucwords function - converts the first character of each word in a string to uppercase.
There are no problems with the symbols of the English alphabet:
"; // converts the first character of each word in the string to uppercase echo ucwords ($ str);?>
Test string Test String
But there are problems with the Cyrillic alphabet:
"; // converts the first character of each word in the string to uppercase echo ucwords ($ str);?>
Test line test line
For PHP, there are typical cases when functions "bad" or do not work at all with Cyrillic. Some functions with the mb prefix solve problems with the Cyrillic alphabet. For example, mb_strtolower - converting a string to lowercase. Unlike strtolower (), what a character is a letter is determined based on the properties of the Unicode character.
To solve the problem, let's define the function mb_ucfirst (string str [, string encoding]), which will process Unicode characters.
To uppercase the first character of each word in a string, simply use mb_convert_case in MB_CASE_TITLE mode.
Case change functions
strtolower
Converts characters in a string to lowercase.
Syntax:
string strtolower (string str);
Converts a string to lowercase. Returns the translation result.
It should be noted that if the locale is incorrectly configured, the function will produce, to put it mildly, strange results when working with Cyrillic letters.
$ str = "HeLLo World";
$ str = strtolower ($ str);
// prints hello world
strtoupper
Converts the specified string to uppercase.
Syntax:
string strtoupper (string str);
Converts a string to uppercase. Returns the result of the transformation. This function works well with English letters, but it can be weird with Russian letters.
$ str = "Hello World";
$ str = strtoupper ($ str);
// prints HELLO WORLD
Converts the first character of a string to uppercase.
Syntax:
string ucfirst (string str);
Returns a string whose first character is uppercase.
$ str = "hello world";
$ str = ucfirst ($ str);
// prints Hello world
Converts the first character of each word in a string to uppercase.
Syntax:
string ucwords (string str);
Returns a string that capitalizes the first character of each word in the string.
A word here means a section of a line preceded by a whitespace character: space, line feed, page feed, carriage return, horizontal and vertical tabs.
Cyrillic characters may not be converted correctly.
$ str = "hello world";
$ str = ucfirst ($ str);
// prints Hello World
From the book Linux Kernel Modules Developer's Encyclopedia author Pomerantz Ori From the book The Human Factor in Programming the author Constantine Larry L54 Agents of Change One fish, making the right movement at the right moment, can change the course of an entire school. In a software development group, the success of introducing a new tool or improved version control method often depends on
From the book Using the STL Effectively by Meyers ScottTip 35. Implement simple case insensitive string comparisons using mismatch or lexicographical_compare One of the questions frequently asked by STL newbies is "How does the STL compare strings in a case insensitive manner?" The simplicity of this question is deceiving. Comparisons
From the book Fundamentals of Object Oriented Programming by Meyer BertrandCase-insensitive String Comparison Matt Ostern If you've ever written a program that uses strings (who, you ask, hasn't?), Most likely you've encountered a typical situation - two strings differing only in case
From the book TCP / IP Architecture, Protocols, Implementation (including IP version 6 and IP Security) by Faith Sidney M From the book XSLT Technology the author Valikov Alexey NikolaevichChange and Consistency Software development, as mentioned, has a lot to do with repeatability. To understand the technical difficulty of reuse, one must understand the nature of repeatability. Despite the fact that programmers usually repeat some and
From the book Developing Applications in Linux. Second edition the author Johnson Michael K.11.8.2 Move and change What happens if the user moves the computer to a different location by connecting it to a different network or subnet? At boot time, a computer using DHCP will automatically change its IP address and subnet mask, and if necessary -
From the C ++ book. Collection of recipes the author Diggins Christopher22.10.3 DNS Changes A new type of resource record, AAAA, maps domain names to IP version 6 addresses. Example of such record: MICKEY IN AAAA 4321: 0: 1: 2: 3: 4: 567: 89AB Reverse lookup must also be provided ... To translate addresses to names for IPv6, you will need to add new domains. Reverse lookup
From the book Linux and UNIX: Shell Programming. Developer's guide. by Teinsley David From the book Office Computer for Women the author Evgeniya PasternakChanges in XPath 2.0 The development version of the XPath language, due to the integration with XQuery, will obviously undergo major changes. The new specification is already split into two documents: a document describing the data model and a document describing functions and operators. Therefore on
From the HTML, XHTML and CSS book 100% author Quint Igor11.7.2. Changes to the code Once the data structures are reflected correctly in parseCommand (), it becomes quite easy to run commands in the correct order with enough attention to detail. First of all, we add a loop to parseCommand () to start child processes,
From the author's book4.13. Performing a Case-insensitive String Comparison Problem You have two strings and you want to know if they are not equal in a case-insensitive manner. For example, "cat" is not equal to "dog", but "Cat" must be equal to "cat", "CAT", or "caT". Solution Compare the strings using the standard
From the author's book4.14. Performing a Case-insensitive String Search Problem You want to find a substring in a string, ignoring the case difference. Solution Use the standard transform and search algorithms defined in
8.1.8. Ignore Case By default, grep is case sensitive. To search in a case insensitive manner, use the -i option. In the data.f file, the month Sept appears in both upper and lower case. Therefore for
From the author's bookChanges If there are many changes in the document, it is convenient to use this group of buttons. For example, you see a change and you agree with it. Place the cursor in it and click the Accept button. The highlight of the correction disappears and it blends seamlessly with your text.
From the author's bookTag and attribute names are case-insensitive In HTML documents, tag and attribute names are case-insensitive, so, for example, writing