php replace multiple characters in string code example

Example 1: php str_replace multiple

str_replace(array(':', '\\', '/', '*'), ' ', $string);

Example 2: php str_replace multiple

print str_replace(
    array("search1","search2"),
    array("replace1", "replace2"),
    "search1 search2"
);

Example 3: replace multiple characters one string php

// Provides: You should eat pizza, beer, and ice cream every day
$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = ["fruits", "vegetables", "fiber"];
$yummy   = ["pizza", "beer", "ice cream"];

$newPhrase = str_replace($healthy, $yummy, $phrase);

Tags:

Php Example