Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - String Functions
What will be the output of the following PHP code?
$str = "Hello World!";
echo strlen($str);
A12
B10
C11
D13
Step-by-Step Solution
Solution:
  1. Step 1: Count characters in the string including spaces and punctuation

    The string "Hello World!" has 12 characters: 5 letters + 1 space + 5 letters + 1 exclamation mark.
  2. Step 2: Confirm strlen() counts all characters

    strlen($str) returns 12 because it counts every character.
  3. Final Answer:

    12 -> Option A
  4. Quick Check:

    Count all characters including spaces and punctuation [OK]
Quick Trick: Count every character including spaces and symbols [OK]
Common Mistakes:
  • Ignoring spaces in count
  • Forgetting punctuation counts
  • Assuming strlen() excludes special characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes