0
0
PHPprogramming~5 mins

String replace functions in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Astr_ireplace()
Bstr_replace()
Csubstr_replace()
Dstrtolower()
What will str_replace('a', 'b', 'apple') return?
Abpple
Bapple
Cbppleapple
Dbppleappleb
How can you replace multiple different words in one call using str_replace()?
ABy using regular expressions
BBy calling <code>str_replace()</code> multiple times
CBy passing arrays for search and replace parameters
DBy using <code>str_ireplace()</code>
What does the optional fourth parameter of str_replace() store?
AThe replaced string
BLength of the original string
CBoolean success/failure
DNumber of replacements made
Which function would you use to replace a substring at a specific position in PHP?
Astr_replace()
Bsubstr_replace()
Cstr_ireplace()
Dstrpos()
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.