Recall & Review
beginner
What does the PHP function
str_replace() do?It replaces all occurrences of a search string with a replacement string within another string.
Click to reveal answer
beginner
How do you replace the word 'cat' with 'dog' in the string 'The cat is cute' using PHP?
Use
str_replace('cat', 'dog', 'The cat is cute') which returns 'The dog is cute'.Click to reveal answer
intermediate
What is the difference between
str_replace() and str_ireplace() in PHP?str_replace() is case-sensitive, while str_ireplace() ignores case when replacing strings.Click to reveal answer
intermediate
Can
str_replace() replace multiple different strings at once?Yes, by passing arrays for the search and replace parameters, it can replace multiple strings in one call.
Click to reveal answer
intermediate
What does the optional fourth parameter of
str_replace() do?It stores the number of replacements made as an integer.
Click to reveal answer
Which PHP function replaces all occurrences of a string, ignoring case?
✗ Incorrect
str_ireplace() replaces strings without considering case differences.What will
str_replace('a', 'b', 'apple') return?✗ Incorrect
All 'a' characters are replaced with 'b', so 'apple' becomes 'bpple'.
How can you replace multiple different words in one call using
str_replace()?✗ Incorrect
Passing arrays lets you replace multiple strings in one function call.
What does the optional fourth parameter of
str_replace() store?✗ Incorrect
It stores the count of how many replacements were done.
Which function would you use to replace a substring at a specific position in PHP?
✗ Incorrect
substr_replace() replaces part of a string at a given position.Explain how to replace multiple different words in a string using PHP string replace functions.
Think about how arrays can be used as inputs.
You got /3 concepts.
Describe the difference between
str_replace() and str_ireplace().Focus on how they treat uppercase and lowercase letters.
You got /3 concepts.