Question 1Medium
Which function is used to strip whitespace( or other characters)from the beginning and end of string?
- trim_str
- strip_str
- strip
- trim
Answer: D. trim
Explanation
This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters:
o " " (ASCII 32 (0x20)), an ordinary space.
o "\t" (ASCII 9 (0x09)), a tab.
o "\n" (ASCII 10 (0x0A)), a new line (line feed).
o "\r" (ASCII 13 (0x0D)), a carriage return.
o "\0" (ASCII 0 (0x00)), the NUL-byte.
o "\x0B" (ASCII 11 (0x0B)), a vertical tab.
Step-by-step solution
- The question asks for the function that removes whitespace or other characters from both ends of a string.
- Trim removes characters from the start and the end of a string.
- Trim_str and strip_str are not PHP functions, and strip alone is not the trimming function.
- The correct answer is option D, trim.
Why the other options are wrong
- A. Trim_str is not a PHP function name; the function is trim.
- B. Strip_str is not a PHP function name and does not trim the ends.
- C. Strip is not the trimming function.
Tip: For trimming questions, the name is trim; ends are both sides, so think both-end cleaning.