Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - String Functions
What will be the output of this PHP code?
$text = "Hello World!";
echo str_replace("World", "PHP", $text);
APHP World!
BHello World!
CHello PHP World!
DHello PHP!
Step-by-Step Solution
Solution:
  1. Step 1: Understand str_replace() effect

    It replaces 'World' with 'PHP' in the string "Hello World!".
  2. Step 2: Apply replacement

    Resulting string becomes "Hello PHP!".
  3. Final Answer:

    Hello PHP! -> Option D
  4. Quick Check:

    Replace 'World' with 'PHP' = Hello PHP! [OK]
Quick Trick: str_replace() changes all matching substrings [OK]
Common Mistakes:
  • Expecting no change
  • Replacing wrong substring
  • Confusing output with concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes