w3resource
php Programming Exercies

PHP String Exercises : Change the case of letters or words

PHP String: Exercise-1 with Solution

Write a PHP script to : -

a) transform a string all uppercase letters.
b) transform a string all lowercase letters.
c) make a string's first character uppercase.
d) make a string's first character of all the words uppercase.

Pictorial Presentation:

PHP String Exercises: Change the case of letters or words

Sample Solution:

PHP Code:

<?php
//all uppercase letters
print(strtoupper("the quick brown fox jumps over the lazy dog."))."\n";
//all lowercase letters
print(strtolower("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"))."\n";
// make a string's first character uppercase
print(ucfirst("the quick brown fox jumps over the lazy dog."))."\n";
// make a string's first character of all the words uppercase
print(ucwords("the quick brown fox jumps over the lazy dog."))."\n";
?>

Sample Output:

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.                
the quick brown fox jumps over the lazy dog                 
The quick brown fox jumps over the lazy dog.                
The Quick Brown Fox Jumps Over The Lazy Dog.

Flowchart :

Flowchart: Change the case of letters or words

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: PHP String Exercises Home.
Next: Write a PHP script to split the specific string.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming