Bird
0
0

What does the PHP function substr($text, 2, 3) do?

easy📝 Conceptual Q11 of 15
PHP - String Functions
What does the PHP function substr($text, 2, 3) do?
AExtracts the first 3 characters of $text
BExtracts 2 characters from $text starting at index 3
CExtracts 3 characters from $text starting at index 2
DExtracts the last 3 characters of $text
Step-by-Step Solution
Solution:
  1. Step 1: Understand substr parameters

    The first parameter is the string, the second is the start index (0-based), and the third is the length of substring.
  2. Step 2: Apply to given function

    Starting at index 2 means the third character, and length 3 means extract 3 characters from there.
  3. Final Answer:

    Extracts 3 characters from $text starting at index 2 -> Option C
  4. Quick Check:

    substr(string, 2, 3) = 3 chars from index 2 [OK]
Quick Trick: Remember start is zero-based, length is how many chars [OK]
Common Mistakes:
  • Confusing start index with length
  • Thinking start counts from 1 instead of 0
  • Assuming length is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes