PHP substr_count () function gets the number of substring occurrences, phpsubstr_count_php tutorial

Source: Internet
Author: User
Tags strcmp

The Substr_count () function in PHP gets the number of occurrences of substrings, Phpsubstr_count


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 = "Help the home to provide 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.

Articles you may be interested in:

    • PHP uses the STRSTR () function to obtain a method for all characters after a specified string
    • PHP strncmp () function compares the first 2 characters of a two string method
    • STRNATCMP () function "Natural sorting algorithm" in PHP for string comparison usage analysis (compare strcmp function)
    • strcmp () and strcasecmp () function strings in PHP comparison usage analysis
    • Analysis of substr function string interception usage in PHP
    • PHP uses Trim function to remove left and right spaces and special character instances
    • PHP encapsulated string encryption and decryption function
    • The most accurate PHP intercept string length function
    • What to do if you use substr () in PHP to intercept strings in Chinese characters.
    • Summary of examples of PHP common string manipulation functions

http://www.bkjia.com/PHPjc/1089572.html www.bkjia.com true http://www.bkjia.com/PHPjc/1089572.html techarticle The Substr_count () function in PHP gets the number of occurrences of substrings, Phpsubstr_count This example describes how the Substr_count () function in PHP gets the number of occurrences of a substring. Share to ...

  • 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.