php count标签出现在字符串中

时间:2018-01-29 11:36:52

标签: php

我正在寻找一种方法来计算字符串中制表符的出现次数。

substr_count("this    means   nothing", "\t");

返回0,但我希望测试字符串中有两个制表位。

如果可能,我不想使用正则表达式(出于性能原因)。

提前致谢。

2 个答案:

答案 0 :(得分:0)

$text2 = 'this    means   nothing';
echo substr_count($text2, 't');

试试吧 http://php.net/manual/en/function.substr-count.php

答案 1 :(得分:0)

傻傻的,

像Friedrich Roell评论的那样,我的编辑确实将标签转换为空格。

substr_count()工作正常。

谢谢。