【发布时间】:2014-03-07 21:17:29
【问题描述】:
我有一个非常简单的代码,它替换字符串中的特定值,然后分解它。
但我需要在爆炸后对字符串进行计数,这是我的示例
$exclude=array();
$exclude[0]="with";
$exclude[1]="on";
$search_string="Boy with a t-shirt walking on the road";
echo str_word_count($search_string);
//the str_replace is suppose to remove the word "with" and "on" from string
// count search string before explode
$sch2 = str_replace($exclude,"", trim($search_string));
$sch=explode(" ",trim($sch2));
echo count($sch);
//count search string after explode
//The result of the second count after exploding is suppose to be 6 and NOT 8
但是当我计算爆炸后的 $sch 字符串时,它给了我 8
似乎有什么地方做错了,任何帮助将不胜感激。谢谢
【问题讨论】:
-
试试
var_dump($sch);- 也许 $sch 不包含您认为的内容?
标签: php str-replace explode