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

Source: Internet
Author: User
In PHP, the substr_count () function is used to obtain the number of occurrences of a substring, phpsubstr_count. In PHP, the substr_count () function obtains the number of occurrences of a substring. phpsubstr_count this article describes how to obtain the occurrences of a substring using the substr_count () function in PHP. How to use the substr_count () function in PHP to obtain the occurrence times of a substring, phpsubstr_count

This example describes how to obtain the occurrence times of a substring using the substr_count () function in PHP. 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 = "($ 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.