Bird
0
0

What does the PHP function trim() do to a string?

easy📝 Conceptual Q11 of 15
PHP - String Functions
What does the PHP function trim() do to a string?
ARemoves all spaces inside the string
BRemoves whitespace from both the beginning and end of the string
CRemoves only the first character of the string
DConverts the string to uppercase
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of trim()

    The trim() function removes unwanted whitespace characters from the start and end of a string.
  2. Step 2: Compare options with function behavior

    Only Removes whitespace from both the beginning and end of the string correctly describes removing whitespace from both ends, not inside or changing case.
  3. Final Answer:

    Removes whitespace from both the beginning and end of the string -> Option B
  4. Quick Check:

    trim() removes spaces at both ends [OK]
Quick Trick: trim() cleans spaces only at string ends, not inside [OK]
Common Mistakes:
  • Thinking trim() removes spaces inside the string
  • Confusing trim() with strtoupper()
  • Assuming trim() removes only from one side

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes