This function is used for find and replace on string or an array.We can apply this function on full list of array and replace with specific staring or array of string.This function contain for parameter find,replace,source Data and count.In this function by default limit is -1(means no limit) and count is optional.
Syntax:
- preg_replace(find,replace,$data,$limit,$count);
Example:
- $data=” We can give it one thing to find and replace”;
- //create arrays
- $find = array (‘/ replace /’, ‘/ find /’);
- $replace = array (‘Replace’, ‘Find’);
- // replace with array values
- echo preg_replace ($find, $replace, $data);
// replace with array values
echo preg_replace ($find, $replace, $data);