PHP Find string Occurrences function Introduction _php tutorial

Source: Internet
Author: User
Finding the number of occurrences of a string in PHP can be done by using the Substr_count () function, and I'll give you a detailed introduction to these functions.

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

/$haystack represents a female string, $needl represents the character to find
$offset represents the starting point for the lookup, $length the length of the lookup, which is an optional parameter


Instance:

The code is as follows Copy Code

$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 Copy Code

$str = ' Http://www.bkjia.com Love program Net _ Software Programming Tutorial _ Software Design Communication _ character occurrences ';
Echo Substr_count ($str, ' W '). '
';
Echo Substr_count ($str, ' t '). '
';
Echo Substr_count ($str, ' Love program Net ');
?>

The output is:
Here are the output results
3
2
1

Share some string lookup functions again

strstr-finding the first occurrence of a string
Stristr strstr case-insensitive version
Strpos-Find where the string first appears
String substr (string $string, int $start [, int $length])
String STRRCHR (String $haystack, mixed $needle)
Strripos-Calculates the location of the last occurrence of the specified string in the target string (case insensitive)
Stripos-Find where the string first appears (not case-sensitive)
Strrpos-Calculates the position of the last occurrence of the specified string in the target string


http://www.bkjia.com/PHPjc/445621.html www.bkjia.com true http://www.bkjia.com/PHPjc/445621.html techarticle Finding The number of occurrences of a string in PHP can be done by using the Substr_count () function, and I'll give you a detailed introduction to these functions. 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.