用对立面替换字符串中的单词

时间:2015-03-31 19:36:15

标签: php arrays str-replace

我正在尝试将字符串中的某些单词替换为对立面。

我试过了:

$input = "the big black cat likes the small white dog";
$array_oldwords = array("black","white","big","small");
$array_newwords = array("white","black","small","big");

$input = str_replace($array_oldwords,$array_newwords,$input);`

所需的输出是:

the small white cat likes the big black dog

但实际上是:

the big black cat likes the big black dog

如何实现这一目标?

0 个答案:

没有答案