Bird
0
0

Find the mistake in this PHP code snippet:

medium📝 Debug Q7 of 15
PHP - String Functions
Find the mistake in this PHP code snippet:
$str = "Example";
echo substr($str, 2, 10);
ALength exceeds string length but no error occurs
BStart index 2 is invalid
Csubstr requires length less than string length
DMissing semicolon after echo
Step-by-Step Solution
Solution:
  1. Step 1: Check parameters

    Start index 2 is valid, length 10 exceeds remaining string length.
  2. Step 2: Understand substr behavior

    substr returns substring from start to end if length exceeds string length, no error occurs.
  3. Final Answer:

    Length exceeds string length but no error occurs -> Option A
  4. Quick Check:

    substr handles length > string length gracefully [OK]
Quick Trick: substr returns till end if length too big [OK]
Common Mistakes:
  • Expecting error on large length
  • Confusing start index validity
  • Syntax errors unrelated to substr

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes