Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - String Functions
Identify the error in this PHP code:
$text = "Hello";
str_replace("H", "J");
echo $text;
AMissing third argument (subject) in str_replace()
Bstr_replace() cannot replace single characters
Cecho statement is incorrect
DNo error, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check str_replace() parameters

    str_replace() requires three parameters: search, replace, and subject string.
  2. Step 2: Identify missing argument

    The code calls str_replace() without the subject string, so it does nothing.
  3. Final Answer:

    Missing third argument (subject) in str_replace() -> Option A
  4. Quick Check:

    All three parameters required = Missing third argument (subject) in str_replace() [OK]
Quick Trick: Always provide subject string as third argument [OK]
Common Mistakes:
  • Omitting subject string
  • Expecting in-place string change
  • Misunderstanding function return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes