Counting the number of specific characters inside string

前端 未结 6 1090
鱼传尺愫
鱼传尺愫 2020-12-31 18:44

I\'m sorry, I just found a new problem due to my question about: Get The Number of Sepecific String Inside String.

I have been trying hard, how to find the number of

6条回答
  •  情歌与酒
    2020-12-31 18:53

    $k_count = substr_count($string, 'K') - substr_count($string, 'K-');
    $k1_count = substr_count($string, 'K-1');
    

    or

    Counting K not followed by dash as follows:

    $k_count = preg_match_all('/*K(?!-)/*', $string, $out);
    

提交回复
热议问题