Skip to content

PHP Tutorial Strings

Changing Case

Lesson 67 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

PHP has four everyday functions for changing the case of text.

FunctionWhat it doesExample result
strtoupper()ALL CAPITALSHELLO WORLD
strtolower()all small lettershello world
ucfirst()Capital first letterHello world
ucwords()Capital first letter of each wordHello World
index.php
PHP
<?php
$text = "hello wORLD";

echo strtoupper($text) . "\n";
echo strtolower($text) . "\n";
echo ucfirst($text) . "\n";
echo ucwords($text);
Output
OUTPUT
HELLO WORLD
hello world
Hello wORLD
Hello WORLD

ucfirst() and ucwords() do not lower the other letters. To normalise text, lower it first.

index.php
PHP
<?php
$name = "aNiL kUMAR";

echo ucwords(strtolower($name));
Output
OUTPUT
Anil Kumar

Compare text without caring about case

Lower both sides before comparing.

index.php
PHP
<?php
$typed = "YES";

if (strtolower($typed) === "yes") {
    echo "Confirmed";
}
Output
OUTPUT
Confirmed

Lowercase an email

Email addresses are usually compared in lowercase.

index.php
PHP
<?php
$email = " Ravi@Example.COM ";

echo strtolower(trim($email));
Output
OUTPUT
ravi@example.com

Names have exceptions

ucwords() is great for simple cases, but names like “McDonald” or “van der Berg” will be changed incorrectly. Do not force the case of real names. Accept what the user typed.

Text with accents

The plain functions work on English letters. For other alphabets, use the mb_ versions.

index.php
PHP
<?php
echo mb_strtoupper("zoë café");
Output
OUTPUT
ZOË CAFÉ

In PHP 8.4 there are also mb_ucfirst() and mb_lcfirst().

lightbulb
Slugs are lowercase
A URL like /blog/My-Post and /blog/my-post can be seen as different pages. Make slugs lowercase with strtolower().