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 = 'hello world!'; $foo = ucwords($foo); // Hello World! $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! $bar = ucwords(strtolower($bar)); // Hello World! ?>
Online learning video recommendation: php video tutorial
The first letter of the first word becomes uppercase: ucfirst()
<?php $foo = 'hello world!'; $foo = ucfirst($foo); // Hello world! $bar = 'HELLO WORLD!'; $bar = ucfirst($bar); // HELLO WORLD! $bar = ucfirst(strtolower($bar)); // Hello world! ?>
The first letter of the first word becomes lowercase: lcfirst()
<?php $foo = 'HelloWorld'; $foo = lcfirst($foo); // helloWorld $bar = 'HELLO WORLD!'; $bar = lcfirst($bar); // hELLO WORLD! $bar = lcfirst(strtoupper($bar)); // hELLO WORLD! ?>
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!