PHP English letter case conversion function

WBOY
Release: 2016-07-25 09:13:10
Original
1007 people have browsed it

Example 1, convert the first letter of each word 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, the first letter of the first word changes Uppercase: 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, the first letter of the first word changes 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. Change all letters to uppercase: strtoupper()
  8. Change all letters to lowercase: strtolower()
Copy Code

The above introduces a total of five English letter case conversion functions, namely ucwords, ucfirst, lcfirst, strtoupper, and strtolower, each with its own use.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template