如何使用php计算字符串中的破折号( - )? [重复]

How to count only (-) in string using php ?

normally i usually use below code to count all char length in string using php

$count = mb_strlen( $string );

But i want to know how can i count only dash sign (-) in string using php ?

EG:

$string = "1-2-3-4-5-";

after count dash sign (-) result will be 5

</div>

The most simple is use the function substr_count()

$str = 'some-class-of-css';
echo substr_count($str, '-'); //3