(PHP 4, PHP 5, PHP 7)
substr_count — 锟斤拷锟斤拷锟街达拷锟斤拷锟街的达拷锟斤拷
$haystack
, string $needle
[, int $offset
= 0
[, int $length
]] ) : int
substr_count() 锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷needle
锟斤拷锟街凤拷锟斤拷 haystack
锟叫筹拷锟街的达拷锟斤拷锟斤拷注锟斤拷 needle
锟斤拷锟街达拷小写锟斤拷
Note:
锟矫猴拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷氐锟斤拷址锟斤拷锟斤拷锟斤拷渭锟斤拷锟斤拷锟斤拷锟斤拷锟接★拷
haystack
锟节达拷锟街凤拷锟斤拷锟叫斤拷锟斤拷锟斤拷锟斤拷锟斤拷
needle
要锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷
offset
锟斤拷始锟斤拷锟斤拷锟斤拷偏锟斤拷位锟矫★拷锟斤拷锟斤拷歉锟斤拷锟斤拷锟斤拷痛锟斤拷址锟斤拷锟侥┪诧拷锟绞纪筹拷啤锟�
length
指锟斤拷偏锟斤拷位锟斤拷之锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟饺★拷锟斤拷锟狡拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟饺的和达拷锟斤拷 haystack
锟斤拷锟杰筹拷锟饺o拷锟斤拷锟接★拷锟斤拷锟斤拷锟较拷锟�
锟斤拷锟斤拷锟侥筹拷锟斤拷 length 锟角达拷 haystack
锟斤拷末尾锟斤拷始统锟狡的★拷
锟矫猴拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
锟芥本 | 说锟斤拷 |
---|---|
7.1.0 |
锟斤拷始支锟街革拷锟斤拷锟斤拷 offset 锟斤拷 length 锟斤拷
|
5.1.0 |
锟斤拷锟斤拷 offset 锟斤拷 length 锟斤拷锟斤拷锟斤拷
|
Example #1 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');
?>