Bird
0
0

Why does trim() remove characters from both ends but not from the middle of a string in PHP?

hard📝 Conceptual Q10 of 15
PHP - String Functions
Why does trim() remove characters from both ends but not from the middle of a string in PHP?
ABecause trim() is designed to remove characters only from the middle
BBecause trim() removes all characters including middle ones
CBecause trim() only scans and removes characters from the start and end, not inside
DBecause trim() replaces characters inside the string with spaces
Step-by-Step Solution
Solution:
  1. Step 1: Understand trim() behavior

    trim() scans from the start and end of the string and removes matching characters until it hits a different character.
  2. Step 2: Reason why middle characters stay

    Characters inside the string are not scanned or removed because trim() only targets the edges.
  3. Final Answer:

    Because trim() only scans and removes characters from the start and end, not inside -> Option C
  4. Quick Check:

    trim() removes only edges, not middle [OK]
Quick Trick: trim() only removes from string edges [OK]
Common Mistakes:
  • Thinking trim() removes characters inside string
  • Assuming trim() replaces characters
  • Confusing trim() with str_replace()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes