Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - String Functions
What will be the output of this PHP code?
$str = "xxHello Worldxx";
echo trim($str, "x");
AxxHello Worldxx
BHello World
CHello Worldxx
DxxHello World
Step-by-Step Solution
Solution:
  1. Step 1: Understand trim() with character mask

    trim() removes specified characters from both ends of the string.
  2. Step 2: Apply trim() to the string

    Characters "x" at the start and end are removed, so "xxHello Worldxx" becomes "Hello World".
  3. Final Answer:

    Hello World -> Option B
  4. Quick Check:

    trim() with "x" removes x's both ends [OK]
Quick Trick: trim() removes specified chars from both ends [OK]
Common Mistakes:
  • Thinking trim() removes characters inside the string
  • Confusing trim() with rtrim() or ltrim()
  • Not specifying the character mask correctly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes