Php query string occurrences function introduction _ PHP Tutorial

Source: Internet
Author: User
Description of the function used to find the number of occurrences of a string in php. You can use the substr_count () function to find the number of occurrences of a string in php. I will introduce these functions to you in detail. Substr_count ($ haystack, $ needle [. you can use the substr_count () function to find the number of occurrences of a string in php. next I will introduce these functions in detail.

Substr_count ($ haystack, $ needle [, $ offset [, $ length])

/$ Haystack indicates the parent string, and $ needl indicates the character to be searched
// $ Offset indicates the start point of the search, and $ length indicates the length of the search, all of which are optional parameters.


Instance:

The code is as follows:

$ Str = "this is a test ";
Echo substr_count ($ str, 'is ').'
';
Echo substr_count ($ str, 'is ', 3 ).'
';
Echo substr_count ($ str, 'is ', 3, 3 ).'
';
?>


Instance:

The code is as follows:

$ Str = 'http: // www.bkjia.com Love program net_getting started with software programming _ Software Design Exchange _ character occurrences ';
Echo substr_count ($ str, 'w ').'
';
Echo substr_count ($ str, 'T ').'
';
Echo substr_count ($ str, 'Love program net ');
?>

Output result:
// The output result is as follows:
3
2
1

Then share some string lookup functions

Strstr-first appearance of the search string
Stristr strstr case-insensitive version
Strpos-locate the first occurrence of a string
String substr (string $ string, int $ start [, int $ length])
String strrchr (string $ haystack, mixed $ needle)
Strripos-calculate the position of the last occurrence of the specified string in the target string (case insensitive)
Stripos-locate the first occurrence of a string (no size difference)
Strrpos-calculate the position of the last occurrence of the specified string in the target string


The aggregate () function is implemented. I will introduce these functions to you in detail. Substr_count ($ haystack, $ needle [,...

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.