【发布时间】:2018-03-16 18:53:01
【问题描述】:
以下代码的问题在于,它从字符串中删除了字符,而不是单词。
<?php
$str = "In a minute, remove all of the corks from these bottles in the cellar";
$useless_words = array("the", "of", "or", "in", "a");
$newstr = str_replace($useless_words, "", $str);
//OUTPUT OF ABOVE: "In mute, remove ll cks from se bottles cellr"
?>
我需要输出:分钟,从这些酒瓶地窖中取出所有软木塞
我假设我不能使用str_replace()。我该怎么做才能做到这一点?
.
【问题讨论】:
标签: string replace str-replace words