PHP case sensitive String Replace
Required: String to be searched for matching, can be an array
Required: String to be replaced if found using search string, can be an array
Required : String on which search and replace to be applied, can be an array
Optional: Stores the number of replacements performed.
Output is a string or array after performing search and replace over the input string
To replace a part of the string with another string we will use str_replace function in PHP. This function will replace all the occurrence of the string we target and will replace with the string we supply.
Here is an example.
Output is here
If you run the above code your will see result like this
Here you can see the text html is replace by PHP but HTML is not replaced.
So str_replace() is a case sensitive string replacing function. We can use str_ireplace() to get case insensitive string replacement
Find & ReplaceWe can create an array of search strings and an array or replace strings. These two array we can apply to search and replace words from the content. The matching words will be replace by matching strings from replace array. Original String
Here is the code
Highlighting the changes.Replace the replace array with additional tags to highlight the replaced string.
Using optional parameter countWe can store number of search and replacement carried out using str_replace function.
Output is here
Read how search & replace is used to change content of a page
Subscribe to our YouTube Channel here
This article is written by plus2net.com team. https://www.plus2net.com