Recall & Review
beginner
What does the
trim() function do in PHP?The
trim() function removes whitespace or other predefined characters from the beginning and end of a string.Click to reveal answer
beginner
How do
ltrim() and rtrim() differ from trim()?ltrim() removes whitespace or characters only from the start (left) of a string, while rtrim() removes them only from the end (right). trim() removes from both ends.Click to reveal answer
beginner
What is the default character set removed by
trim() if no second argument is given?By default,
trim() removes whitespace characters including space, tab, newline, carriage return, NULL byte, and vertical tab.Click to reveal answer
intermediate
How can you remove specific characters using
trim()?You can pass a second argument to
trim() listing the characters to remove. For example, trim($str, "xyz") removes 'x', 'y', and 'z' from both ends of $str.Click to reveal answer
beginner
What will
rtrim("Hello World!!!", "!") return?It will return
"Hello World" because rtrim() removes all trailing exclamation marks from the right end of the string.Click to reveal answer
Which PHP function removes whitespace from both the start and end of a string?
✗ Incorrect
trim() removes whitespace from both ends, while ltrim() and rtrim() remove from left or right only.What does
ltrim(" Hello") return?✗ Incorrect
ltrim() removes whitespace from the start (left), so leading spaces are removed.How do you remove only trailing dots from a string
$str?✗ Incorrect
rtrim() removes characters from the right end only.Which characters are removed by default by
trim()?✗ Incorrect
By default,
trim() removes all common whitespace characters.What will
trim("***Hello***", "*") return?✗ Incorrect
The
trim() call removes all '*' characters from both ends.Explain how
trim(), ltrim(), and rtrim() work and when you might use each.Think about cleaning spaces or unwanted characters from user input.
You got /4 concepts.
Describe how to remove specific characters from the start and end of a string using PHP trim functions.
Remember the second argument is a list of characters to remove.
You got /3 concepts.