Home  >  Article  >  Backend Development  >  PHP English letter case conversion function

PHP English letter case conversion function

不言
不言Original
2018-04-09 14:30:431556browse

This article mainly introduces several PHP English letter case conversion functions. Now I share them with you. Friends in need can refer to it

Convert the first letter of each word to uppercase: ucwords()

Copy code The code is as follows:

<?php
$foo = &#39;hello world!&#39;;
$foo = ucwords($foo);             // Hello World!
$bar = &#39;HELLO WORLD!&#39;;
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

The first letter of the first word is capitalized: ucfirst()

Copy code The code is as follows:

<?php
$foo = &#39;hello world!&#39;;
$foo = ucfirst($foo);             // Hello world!
$bar = &#39;HELLO WORLD!&#39;;
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

The first letter of the first word is lowercase: lcfirst()

Copy code The code is as follows:

<?php
$foo = &#39;HelloWorld&#39;;
$foo = lcfirst($foo);             // helloWorld
$bar = &#39;HELLO WORLD!&#39;;
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>

Change all letters to uppercase: strtoupper()
Change all letters to lowercase: strtolower()


##

The above is the detailed content of PHP English letter case conversion function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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