Home > Backend Development > PHP Tutorial > What are the methods to force letters to be converted to uppercase and lowercase in PHP?

What are the methods to force letters to be converted to uppercase and lowercase in PHP?

王林
Release: 2023-04-07 21:24:01
Original
3681 people have browsed it

What are the methods to force letters to be converted to uppercase and lowercase in PHP?

strtoupper() Function converts a string to uppercase.

strtolower() Function converts a string to lowercase.

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

<?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!
?>
Copy after login

Online learning video recommendation: php video tutorial

The first letter of the first word becomes uppercase: ucfirst()

<?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!
?>
Copy after login

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

<?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!
?>
Copy after login

Recommended related article tutorials: php tutorial

The above is the detailed content of What are the methods to force letters to be converted to uppercase and lowercase in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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