Multiple choice php

What can you use to replace like with hate in I like Eminem?

  1. preg_replace("like", "hate", "I like Eminem")

  2. preg_replace("/like/", "hate", "I like Eminem")

  3. preg_replace("/like/", "/hate/", "I like Eminem")

  4. preg_replace("hate", "like", "I like Eminem")

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The PHP function preg_replace performs a regular expression search and replace. Regular expression patterns require delimiters, such as forward slashes, around the search string, making option B the correct syntax. Option A is missing regex delimiters, and option C incorrectly adds delimiters to the replacement string.