How to get the number of occurrences of a substring with the substr_count() function in PHP, phpsubstr_count_PHP tutorial

WBOY
Release: 2016-07-12 09:01:22
Original
1379 people have browsed it

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:

<&#63;php
 $str="帮客之家提供大量脚本代码及脚本特效下载";
 echo substr_count($str,"脚本");
 echo "<br/>";
 echo substr_count($str,"脚本",16);//指定在第16个字符后开始搜索
 echo "<br/>";
 echo substr_count($str,"脚本",16,10);//指定从第16个字符开始往后搜索10个字符结束
&#63;>

Copy after login

The running results are as follows:

3
2
1

Copy after login

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

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template