What will be the output of the following PHP code?
<?php
$str = "Hello! My name is Cameron Fox. Coffee?"
$find = array('/is/','/coffee/');
$replace = array('/was/','/tea/');
echo preg_replace ($find, $replace, $str);
?>
<?php
$str = "Hello! My name is Cameron Fox. Coffee?"
$find = array('/is/','/coffee/');
$replace = array('/was/','/tea/');
echo preg_replace ($find, $replace, $str);
?>
A. Hello! My name was Cameron Fox. tea?
B. Hello! My name is Cameron Fox. tea?
C. Hello! My name is Cameron Fox. Coffee?
D. Hello! My name was Cameron Fox. Coffee?
Answer: Option D
Solution(By Examveda Team)
Coffee was not replaced because the preg_replace function is case sensitive. Therefore it treats coffee and Coffee differently.Related Questions on Regular Expressions
A. 1 and 2
B. 2 and 4
C. 1 and 4
D. 2 and 3
Join The Discussion