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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners