是否可以在preg_replace中使用数组来减少所需的代码?像这样:
$text = "1 2 3";
$array = array(1 => "one", 2 => "two", 3 => "three");
preg_replace($array, $text);
echo $text;
结果:
1 2 3
所需结果:
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);
演示在eval。在