Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
String Manipulation.docx59.1 KB String Manipulation - Solution.docx
59.2 KB
Quick reference
String Manipulation
There are several useful built in PHP functions that allow us to manipulate strings.
When to use
Any time you want to manipulate strings, try one of these functions.
Instructions
Here are some functions to change upper/lower case of strings:
strtoupper($var); // changes all letters to uppercase
ucwords($var); // changes all first letters to uppercase
ucfirst($var); // changes just first letter of first word to uppercase
strtolower($var); // changes all to lowercase
lcfirst($var); // changes first letter of first word to lowercase
This function allows you to replace anything in a string:
str_replace(old, new, variable);
Just change old to the thing you want to change, change new to the new thing, and variable is the source of the string you are changing.
Hints & tips
- str_replace(old, new, variable) to change anything in a string.
- strtoupper($var);
- ucwords($var);
- ucfirst($var);
- strtolower($var);
- lcfirst($var);
Lesson notes are only available for subscribers.