0% found this document useful (0 votes)
53 views1 page

PHP - String Capitalization Functions

PHP has three string capitalization functions: strtoupper converts a string to uppercase, strtolower converts to lowercase, and ucwords capitalizes the first letter of each word. strtoupper and strtolower each take a string as an argument and return the capitalized version, keeping non-alphabetic characters the same. These functions can be used to emphasize text, fit design styles, or standardize string comparisons.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

PHP - String Capitalization Functions

PHP has three string capitalization functions: strtoupper converts a string to uppercase, strtolower converts to lowercase, and ucwords capitalizes the first letter of each word. strtoupper and strtolower each take a string as an argument and return the capitalized version, keeping non-alphabetic characters the same. These functions can be used to emphasize text, fit design styles, or standardize string comparisons.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PHP - String Capitalization Functions

If you've ever wanted to manipulate the capitalization of your PHP strings, then this lesson will be quite
helpful to you. PHP has three primary capitalization related functions: strtoupper, strtolower and ucwords. The
function names are pretty self-explanatory, but why they are useful in programming might be new to you.

Converting a String to Upper Case - strtoupper

The strtoupper function takes one argument, the string you want converted to upper case and returns the
converted string. Only letters of the alphabet are changed, numbers will remain the same.

PHP Code:
$originalString = "String Capitalization 1234";

$upperCase = strtoupper($originalString);
echo "Old string - $originalString <br />";
echo "New String - $upperCase";

Display:
Old string - String Capitalization 1234
New String - STRING CAPITALIZATION 1234

One might use this function to increase emphasis of a important point or in a title. Another time it might be
used with a font that looks very nice with all caps to fit the style of the web page design.
A more technical reason would be to convert two strings you are comparing to see if they are equal. By
converting them to the same capitalization you remove the possibility that they won't match simply because of
different capitalizations.

Converting a String to Lower Case - strtolower

The strtolower function also has one argument: the string that will be converted to lower case.

PHP Code:
$originalString = "String Capitalization 1234";

$lowerCase = strtolower($originalString);
echo "Old string - $originalString <br />";
echo "New String - $lowerCase";

Display:
Old string - String Capitalization 1234
New String - string capitalization 1234

You might also like