我preg_replace($oldWords, $newWords, $string);用来替换单词数组。
我希望替换所有以foointo开头的hello单词,以及所有以barinto开头的单词world
即foo123应该改成hello,foobar应该改成hello,barx5应该改成world,等等。
如果我的数组定义为:
$oldWords = array('/foo/', '/bar/');
$newWords = array('hello', 'world');
然后foo123更改为hello123而不是hello。类似地barx5改变worldx5而不是world
如何替换完整匹配的单词?
谢谢。