Bird
0
0

You have a string $data = "\t Example Text \t" with tabs, newlines, and spaces around it. Which PHP function call will remove all these whitespace characters from both ends?

hard📝 Application Q15 of 15
PHP - String Functions
You have a string $data = "\t Example Text \t" with tabs, newlines, and spaces around it. Which PHP function call will remove all these whitespace characters from both ends?
Atrim($data, " \t\n")
Bltrim($data, " \t")
Crtrim($data)
Dtrim($data)
Step-by-Step Solution
Solution:
  1. Step 1: Understand default trim() behavior

    By default, trim() removes spaces, tabs, newlines, carriage returns, and some other whitespace characters from both ends.
  2. Step 2: Check the character mask in options

    trim($data, " \t\n") explicitly specifies space, tab, and newline characters to remove, but the default trim() already removes these and more, so trim($data) is sufficient and preferred.
  3. Step 3: Analyze other options

    rtrim() and ltrim() remove only one side, so they won't clean both ends.
  4. Final Answer:

    trim($data) -> Option D
  5. Quick Check:

    Use trim() to remove all whitespace from both ends [OK]
Quick Trick: Use trim() to remove all whitespace including tabs and newlines [OK]
Common Mistakes:
  • Using ltrim() or rtrim() when both ends need trimming
  • Assuming trim() removes only spaces, not tabs/newlines
  • Not specifying characters when needed for custom trimming

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes