[php]substr_count — 計算字串出現的次數


官方範例
<?php
$text = 'This is a test';
echo strlen($text); // 14


echo substr_count($text, 'is'); // 2


// 字符串被簡化為 's is a test',因此輸出 1
echo substr_count($text, 'is', 3);


// 字符串被簡化為 's i',所以輸出 0
echo substr_count($text, 'is', 3, 3);


// 因為 5+10 > 14,所以生成警告
echo substr_count($text, 'is', 5, 10);




// 輸出 1,因為該函數不計算重疊字符串
$text2 = 'gcdgcdgcd';
echo substr_count($text2, 'gcdgcd');
?>

arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()