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?
$text = "Hello World!";
echo substr($text, 6, 5);
AWorld
BWorld!
CHello
Dorld!
Step-by-Step Solution
Solution:
  1. Step 1: Identify substring start and length

    Start index is 6 (0-based), length is 5 characters.
  2. Step 2: Extract substring from "Hello World!"

    Index 6 is 'W', next 5 chars are 'World'.
  3. Final Answer:

    World -> Option A
  4. Quick Check:

    substr("Hello World!", 6, 5) = "World" [OK]
Quick Trick: Count characters from zero, then take length chars [OK]
Common Mistakes:
  • Including the exclamation mark mistakenly
  • Starting count from 1 instead of 0
  • Confusing length with end index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes