How to get the number of occurrences of a substring by the substr_count() function in PHP, phpsubstr_count
This article describes the method of getting the number of occurrences of a substring by the substr_count() function in PHP. Share it with everyone for your reference, the details are as follows:
substr_count() in PHP can be used to count the number of occurrences of a substring in a specified string.
The substr_count() function is defined as follows:
substr_count(string,substring,start,length)
Parameter description:
string Required. Specifies the string to be checked.
substring required. Specifies the string to search for.
start is optional. Specifies where in the string to begin the search.
length is optional. Specifies the length of the search.
Sample code is as follows:
<?php
$str="帮客之家提供大量脚本代码及脚本特效下载";
echo substr_count($str,"脚本");
echo "<br/>";
echo substr_count($str,"脚本",16);//指定在第16个字符后开始搜索
echo "<br/>";
echo substr_count($str,"脚本",16,10);//指定从第16个字符开始往后搜索10个字符结束
?>
Copy after login
The running results are as follows:
For more information on PHP string operations, please view the special topic on this site: "Summary of PHP String Usage"
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- How to use the strstr() function in PHP to obtain all characters after a specified string
- The strncmp() function in PHP compares two characters How to determine whether the first two characters of a string are equal
- strnatcmp() function "natural sorting algorithm" in PHP for string comparison usage analysis (compare strcmp function)
- strcmp() and strcasecmp in PHP () Usage analysis of function string comparison
- Usage analysis of substr function string interception in PHP
- PHP uses the trim function to remove left and right spaces and special characters from a string. Example
- PHP encapsulation String encryption and decryption function
- The most accurate PHP function to intercept string length
- What to do if the Chinese garbled problem occurs when using substr() to intercept strings in PHP
- PHP Summary of common string manipulation function examples
http://www.bkjia.com/PHPjc/1089572.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1089572.htmlTechArticleHow to obtain the number of occurrences of a substring with the substr_count() function in PHP, phpsubstr_count This article describes the substr_count( ) function to obtain the number of occurrences of a substring. Share to...