[PHP source code reading] strtolower and strtoupper functions

Source: Internet
Author: User
[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.