The Substr_count () function in PHP gets the number of occurrences of substrings, Phpsubstr_count
This example describes how the Substr_count () function in PHP gets the number of occurrences of substrings. Share to everyone for your reference, as follows:
Substr_count () in PHP can be used to calculate the number of occurrences of a substring of a specified string.
The Substr_count () function is defined as follows:
Substr_count (String,substring,start,length)
Parameter description:
string is required. Specifies the string to be checked.
substring required. Specifies the string to search for.
Start is optional. Specifies where to start the search in the string.
Length is optional. Specifies the length of the search.
The sample code is as follows:
<?php $str = "Help the home to provide a lot of script code and script effects download"; Echo Substr_count ($str, "script"); echo "
"; Echo Substr_count ($str, "script", 16);//Specify to start searching for Echo after the 16th character "
"; Echo Substr_count ($str, "script", 16,10);//Specifies to search for 10 characters from the 16th character End?>
The results of the operation are as follows:
321
Read more about PHP string operations for more information on this site: PHP string Usage Summary
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- PHP uses the STRSTR () function to obtain a method for all characters after a specified string
- PHP strncmp () function compares the first 2 characters of a two string method
- STRNATCMP () function "Natural sorting algorithm" in PHP for string comparison usage analysis (compare strcmp function)
- strcmp () and strcasecmp () function strings in PHP comparison usage analysis
- Analysis of substr function string interception usage in PHP
- PHP uses Trim function to remove left and right spaces and special character instances
- PHP encapsulated string encryption and decryption function
- The most accurate PHP intercept string length function
- What to do if you use substr () in PHP to intercept strings in Chinese characters.
- Summary of examples of PHP common string manipulation functions
http://www.bkjia.com/PHPjc/1089572.html www.bkjia.com true http://www.bkjia.com/PHPjc/1089572.html techarticle The Substr_count () function in PHP gets the number of occurrences of substrings, Phpsubstr_count This example describes how the Substr_count () function in PHP gets the number of occurrences of a substring. Share to ...