Conversion of uppercase and lowercase letters in php

Source: Internet
Author: User
In php, the uppercase/Lowercase conversion functions include: strtolower, strtoupper, ucfirst, ucwords, and so on, this article will introduce how to use these uppercase/Lowercase conversion functions.

1. convert string to lowercase

Strtolower (): This function converts all characters of the input string parameter to lowercase, and puts it back in a small form. the code is as follows:

Echo strtolower ("Hello WORLD! ");

2. convert characters into uppercase letters

Strtoupper (): This function is opposite to the strtolower function. it converts all characters of the passed character parameter to uppercase and returns the string in uppercase. the usage is the same as that of strtolowe (). The code is as follows:

$ Str = "Mary Had A Little Lamb and She LOVED It So ";

$ Str = strtoupper ($ str );

Echo $ str; // Print MARY HAD A LITTLE LAMB AND SHE LOVED IT SO

?>

3. convert the first character of the string to uppercase.

Ucfirst (): This function is used to change the first character of a string to uppercase. This function returns the first character in uppercase. the usage is the same as that of strtolowe (). The code is as follows:

$ Foo = 'Hello world! ';

$ Foo = ucwords ($ foo); // Hello World!

// Open source code phpfensi.com

$ Bar = 'Hello WORLD! ';

$ Bar = ucwords ($ bar); // hello world!

$ Bar = ucwords (strtolower ($ bar); // Hello World!

?>

4. convert the first character of each word in the string to uppercase.

Ucwords (): This function converts the first character of each word in the input string to uppercase. for example, "hello world". after this function is processed, "Hello Word" is returned ". the code is as follows:

$ Foo = 'Hello world! ';

$ Foo = ucfirst ($ foo); // Hello world!

$ Bar = 'Hello WORLD! ';

$ Bar = ucfirst ($ bar); // hello world!

$ Bar = ucfirst (strtolower ($ bar); // Hello world!

?>

5. the first letter is lowercase lcfirst (). The code is as follows:

$ Foo = 'helloworld ';

$ Foo = lcfirst ($ foo); // helloWorld

$ Bar = 'Hello WORLD! ';

$ Bar = lcfirst ($ bar); // hELLO WORLD!

$ Bar = lcfirst (strtoupper ($ bar); // hELLO WORLD!

?>

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.