Is it possible to use an array in preg_replace to reduce the codes needed? So, something like this:
$text = "1 2 3";
$array = array(1 => "one", 2 => "two", 3 => "three");
preg_replace($array, $text);
echo $text;
Result:
1 2 3
Needed Result:
one two three
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject,... preg_replace
$text = "1 2 3";
$array = array(
'/1/' => "one",
'/2/' => "two",
'/3/' => "three");
$text = preg_replace(array_keys($array), $array, $text);
Demo at eval.in (as mentioned in the comments, there is no need to use regex here)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments