0
0
PHPprogramming~5 mins

Trim functions in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Atrim()
Bltrim()
Crtrim()
Dstrip()
What does ltrim(" Hello") return?
A"Hello "
B"Hello" with leading spaces
C"Hello"
D" Hello"
How do you remove only trailing dots from a string $str?
Atrim($str, ".")
Brtrim($str, ".")
Cltrim($str, ".")
Dstrip($str, ".")
Which characters are removed by default by trim()?
AAll non-alphanumeric characters
BSpaces and tabs only
COnly spaces
DWhitespace characters like space, tab, newline, carriage return
What will trim("***Hello***", "*") return?
A"Hello"
B"***Hello"
C"Hello***"
D"***Hello***"
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.