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

How to use the substr_count function in php

藏色散人
Release: 2023-04-06 19:26:02
Original
3396 people have browsed it

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)
Copy after login

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");
?>
Copy after login

Output:

2
Copy after login

php substr_count() function usage example 2

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

Output:

1
Copy after login

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!

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