Home >Backend Development >PHP Tutorial >How to use the substr_count function in php

How to use the substr_count function in php

藏色散人
藏色散人Original
2019-05-24 11:36:433376browse

Usage of substr_count function in php: [substr_count(string,substring,start,length)]. The substr_count function is used to count the number of times a specified string appears in a string.

How to use the substr_count function in php

php The substr_count function is used to count the number of occurrences of a string in another string. Its syntax is substr_count(string,substring,start,length) , the parameter string is required and specifies the string to be checked; substring is required and specifies the string to be searched.

(Recommended tutorial: php video tutorial)

How to use the php substr_count function?

Function: Count the number of occurrences of a string in another string

Syntax:

substr_count(string,substring,start,length)

Parameters:

string required. Specifies the string to be checked.

substring Required. Specifies the string to search for.

start Optional. Specifies where in the string to begin the search.

length Optional. Specifies the length of the search.

Description:

Calculate the number of times a substring appears in a string. Substrings are case-sensitive. This function does not count overlapping substrings. This function generates a warning if the start parameter plus the length parameter is greater than the string length.

php substr_count() function usage example 1

<?php
echo substr_count("I love php.I&#39;m study in php.cn","php");
?>

Output:

2

php substr_count() function usage example 2

<?php
 $str = "This is php.cn test";
echo substr_count($str,"is",3,9);
?>

Output:

1

The above is the detailed content of How to use the substr_count function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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