php 字符串里包含某個字符多少個,包含某個字符個數
方法一:substr_count()函數是一個小字符串在一個大字符串中出現的次數:
$number = substr_count($big_string, $small_string);
<?php
echo substr_count("I love Shanghai. Shanghai is the biggest city in china.","Shanghai");
?>
方法二:用explode進行判斷PHP判斷字符串里包含某個字符多少個,代碼如下:
$tmp = explode($big_string,$small_string);
$number = count($tmp);