Web >> Development >> PHP >> How to search and replace a pattern in a string

Example 1 : example replace all whitespaces with <br> ----------------------------------------------------- $pattern = "/\s+/"; $replace = "<br>"; $string = "quick brown fox"; $newstring = preg_replace($pattern,$replace,$string); $newstring becomes "the<br>quick<br>fox"