How the Substr_count function gets the number of substring occurrences in PHP

Source: Internet
Author: User
This example describes how the Substr_count () function in PHP gets the number of occurrences of substrings. Share to everyone for your reference, as follows:

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

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

The sample code is as follows:

<?php $str = "This site provides a lot of script code and script effects download"; Echo Substr_count ($str, "script"); echo "
"; Echo Substr_count ($str, "script", 16);//Specify to start searching for Echo after the 16th character "
"; Echo Substr_count ($str, "script", 16,10);//Specifies to search for 10 characters from the 16th character End?>

The results of the operation are as follows:

321

Read more about PHP string operations for more information on this site: PHP string Usage Summary

I hope this article is helpful to you in PHP programming.

The above describes the PHP Substr_count function to get the number of substring occurrences of the method, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.