PHP English Letter Case Conversion function

Source: Internet
Author: User

Example 1, the first letter of each word is converted to uppercase: Ucwords ()

    1. $foo = ' Hello world! ';
    2. $foo = Ucwords ($foo); Hello world!
    3. $bar = ' HELLO world! ';
    4. $bar = Ucwords ($bar); HELLO world!
    5. $bar = Ucwords (Strtolower ($bar)); Hello world!
    6. ?>
Copy Code

Example 2, first word capitalized: Ucfirst ()

    1. $foo = ' Hello world! ';
    2. $foo = Ucfirst ($foo); Hello world!
    3. $bar = ' HELLO world! ';
    4. $bar = Ucfirst ($bar); HELLO world!
    5. $bar = Ucfirst (Strtolower ($bar)); Hello world!
    6. ?>
Copy Code

Example 3, first word lowercase: lcfirst ()

    1. $foo = ' HelloWorld ';
    2. $foo = Lcfirst ($foo); HelloWorld
    3. $bar = ' HELLO world! ';
    4. $bar = Lcfirst ($bar); HELLO world!
    5. $bar = Lcfirst (Strtoupper ($bar)); HELLO world!
    6. ?>
    7. All letters capitalized: Strtoupper ()
    8. All Letters lowercase: strtolower ()
Copy Code

The above introduces a total of five English letter case conversion function functions, respectively, Ucwords, Ucfirst, Lcfirst, Strtoupper, Strtolower, each has a use.

  • 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.