How to use the substr_count () function in PHP to obtain the occurrence times of a substring

Source: Internet
Author: User
This article describes how to use the substr_count () function in PHP to obtain the occurrence times of a substring, and analyzes the functions, functions, and usage techniques of the substr_count () function based on examples, for more information about how to use the substr_count () function in PHP to obtain the number of occurrences of a substring, see the following example. We will share this with you for your reference. The details are as follows:

Substr_count () in PHP can be used to calculate the number of times a specified string substring appears.

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 is required. Specifies the string to be searched.
Start is optional. Specifies where to start searching in the string.
Length is optional. Specify the length of the search.

Sample codeAs follows:

<? Php $ str = "script home provides a large number of script code and special script effects downloads"; echo substr_count ($ str, "script"); echo"
"; Echo substr_count ($ str," script ", 16); // specify to search for echo after 16th characters"
"; Echo substr_count ($ str," script ", 16th); // specifies that the search will end with 10 characters starting from characters.

The running result is as follows:

321

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.