← Back to Chapters

PHP String LowerCase & UpperCase Functions

? PHP String LowerCase & UpperCase Functions

? Quick Overview

PHP provides two commonly used string functions, strtolower() and strtoupper(), that allow you to convert a string to lowercase or uppercase. These functions are helpful when you need to standardize or compare strings without being case-sensitive.

? Key Concepts

  • strtolower() converts all alphabetic characters in a string to lowercase.
  • strtoupper() converts all alphabetic characters in a string to uppercase.
  • Non-alphabetic characters remain unchanged.

? Syntax / Theory

Both functions accept a string as input and return a transformed version of that string.

  • strtolower(string $text): string
  • strtoupper(string $text): string

? Example 1: Using strtolower()

? View Code Example
// Convert an uppercase string to lowercase
<?php
$string = "HELLO WORLD";
$lowercase = strtolower($string);
echo $lowercase;
?>

? Output

hello world

? Example 2: Using strtoupper()

? View Code Example
// Convert a lowercase string to uppercase
<?php
$string = "hello world";
$uppercase = strtoupper($string);
echo $uppercase;
?>

? Output

HELLO WORLD

? Interactive Concept Demo

This flow shows how PHP transforms text internally:

Input String ➜ strtolower() ➜ lowercase text

Input String ➜ strtoupper() ➜ uppercase text

? Use Cases

  • Case-insensitive username or email comparisons
  • Formatting headings or titles dynamically
  • Normalizing user input before database storage
  • Text transformations in CMS or form handling

✅ Tips & Best Practices

  • Use strtolower() for comparisons to avoid case mismatch.
  • Use strtoupper() for visual emphasis such as labels or headings.
  • For multibyte strings (UTF-8), consider mb_strtolower() and mb_strtoupper().

? Try It Yourself

  • Create a mixed-case string and convert it fully to lowercase.
  • Convert a lowercase sentence into uppercase.
  • Write a PHP function that toggles case automatically.