[PHP source code reading] in strtolower and strtoupper function string operation functions, string case-sensitivity conversion is also a commonly used function, and its underlying implementation is relatively simple. let's take a look at it.
I have a more detailed description of the PHP source code on github. If you are interested, you can look around and give a star. PHP5.4 source code annotation. You can use the commit record to view the added annotations.
Strtolower
String strtolower (string $ string)
Converts a string to lowercase characters.
Strtoupper
String strtoupper (string $ string)
Converts a string to uppercase or lowercase.
Running example
$str = 'Hello World';$new_str = strtolower($str); // hello world$str = 'hello world';$new_str = strupper($str); // HELLO WORLD
Code running steps
Copy a string
Php_strtolower/php_strtoupper for conversion
Source code explanation
The core operations of both functions are similar. let's talk about strtolower, and the other is similar. The core code of the php_strtolower function is as follows:
C = (unsigned char *) s; e = c + len; // traverse s, one by one to lowercase while (c <e) {* c = tolower (* c ); c ++;} return s;
This function traverses the entire string and converts it to lowercase characters one by one. This is also a classic pointer operation.
The original article is limited in writing, so it is easy to learn. if there is anything wrong with the article, please let us know.
If this article is helpful to you, please click here for recommendations. thank you ^_^
At last, I have a more detailed description of the PHP source code on github. If you are interested, you can look around and give a star. PHP5.4 source code annotation. You can use the commit record to view the added annotations.
For more source code articles, visit the personal homepage to continue viewing: hoohack