如何使用php在下面的段落中找到字母't'的计数

时间:2013-07-16 07:05:04

标签: php

$a='Would you like to have responses to your questions sent to you via email'

for($a as $b=>c){

}

请给我解决方案

4 个答案:

答案 0 :(得分:5)

<?php echo substr_count($a, 't'); ?>

答案 1 :(得分:0)

这是 a 解决方案,但不一定是最好的

$letterCount = array_count_values(
    str_split(strtolower($a))
);
$tCount = (isset($letterCount['t'])) ? $letterCount['t'] : 0;

答案 2 :(得分:0)

$count = preg_match_all('/t/', $str);

答案 3 :(得分:0)

检查一下

<?php

$a = 'Would you like to have responses to your questions sent to you via email';

$t_explod = explode('t', strtolower($a));

echo count($t_explod) - 1;
?>