No one on earth can remember the order of parameters for PHP functions like str_replace. In this post, we go through the parameters of str_replace in PHP, tell you which alternatives there are and how you usually use them with frameworks like Laravel.

The string (or array) to be searched ($string) $find = 'str_replace'; $replacement = 'preg_match'; $string = 'Nobody remembers str_replace parameters so developers google str_replace all the time.'; $result = str_replace($find, $replacement, $string); This results in the result string Nobody remembers preg_match parameters so preg_match is googled a lot..

$string = str_replace($find, $replacement, $string); Optional parameters str_replace in PHP has an optional fourth parameter, the $count variable that returns the numer of replacements during that opration.

$find = ['Nobody', 'remembers']; $replacement = ['Everybody', 'googles']; $string = 'Nobody remembers str_replace parameters.'; $result = str_replace($find, $replacement, $string); The result of this replacement operating is Everybody googles str_replace parameters..
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners