Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q5 of 15
PHP - String Functions
What will this PHP code output?
$str = "  PHP is fun  ";
$trimmed = trim($str);
echo strlen($trimmed);
A13
B10
C15
D9
Step-by-Step Solution
Solution:
  1. Step 1: Understand trim() effect

    trim() removes spaces from the start and end of the string, so " PHP is fun " becomes "PHP is fun".
  2. Step 2: Calculate length of trimmed string

    "PHP is fun" has 10 characters including spaces between words.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    trim() + strlen() = 10 [OK]
Quick Trick: trim() removes spaces; strlen() counts characters [OK]
Common Mistakes:
  • Counting spaces before trimming
  • Confusing trim() with rtrim() or ltrim()
  • Miscounting string length including spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes