str_ireplace(): PHP case in-sensitive String Replace
search: Required: String to be searched for matching, can be an array replace: Required: String to be replaced if found using search string, can be an array main_string: Required : String on which search and replace to be applied, can be an array count: Optional: Stores the number of replacements performed. Output is a string or array after performing search and replace over the input string The main difference between str_replace and str_ireplace is str_replace is a case sensitive string replacement and str_ireplace is a case in-sensitive string search and replacement. str_ireplace function in PHP when applied to a main string, it searches for occurrence of a string and replace them by another string. Example 1
Output is here
Search Array & replace stringThis function can take an array as search string and each element of the array if present is replaced by another string. We can try with an example. If you are searching for a simple example then you can see str_replace function. Here is a sample code which takes an array of search words and replaces them by another word within a string.
Output is here
Search array & replace arrayAs we have seen here we can use an array as search terms and all the elements of the array can be replaced by a replace string. We can also use another array as replacement array and each element is replace by matching element from replacement array, if not element is found then blank string is replaced. Here is the script code for that
Output is here
Using optional parameter count to know the number of replacementsAbove script can be modified to add optional parameter $count. This variable will store the number of search and replacement carried out.
Output is here
Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
![]() | ||||||||||
| ||||||||||