With PHP you can perform a number of capitalization or case-changing operations on strings. You can capitalize all the letters in a string, the first letters of words only, or even the first letter of a string only.
You can also convert parts of a string to lowercase if that is what you need to do.
The PHP capitalization tutorial below will help to get you familiar with the various capitalization and de-capitalization operations.
To capitalize the first character of a string (in other words: make it uppercase), we use the ucfirst function. Look at the code below:
<?php $string = "i love tutorial arena so much"; $result = ucfirst($string); echo $string; echo '<br />'; echo $result; ?>
The output is:
As we can see, the first character of the string has been capitalized.
To capitalize the first character of each word in a string, we use the ucwords function. Look at the code below:
<?php $string = "i love tutorial arena so much"; $result = ucwords($string); echo $string; echo '<br />'; echo $result; ?>
The output is:
As we can see, the first character of each word in the string has been capitalized.
To capitalize an entire string, we use the strtoupper function. Look at the code below:
<?php $string = "i love tutorial arena so much"; $result = strtoupper($string); echo $string; echo '<br />'; echo $result; ?>
The output is:
As we can see, the entire string has been capitalized.
We use the strtolower function to make an entire string lowercase. Look at the code below:
<?php $string = "I LoVe tUtoRIAl ARENA SO MUCH"; $result = strtolower($string); echo $string; echo '<br />'; echo $result; ?>
The output is:
As we can see, the entire string has been converted to lowercase.
Whether you want to change strings to uppercase, to lowercase, or even capitalize every word in a string, it is easily accomplished using PHP capitalization functions. We hope this PHP tutorial was helpful.