This example describes how the PHP lookup string appears. Share to everyone for your reference. The specific methods are as follows:
Looking up the number of occurrences of a string in PHP can be done by the Substr_count () function, and here's a detailed description of these functions.
Substr_count ($haystack, $needle [, $offset [, $length]])
Where parameters:
$haystack represents a parent string, $needl represents the character to find
$offset represents the starting point for the lookup, $length represents the length of the lookup, all optional parameters
The instance code is as follows:
Copy Code code as follows:
<?php
$str = "This is a test";
Echo Substr_count ($str, ' is '). ' <br> ';
Echo Substr_count ($str, ' is ', 3). ' <br> ';
Echo Substr_count ($str, ' is ', 3, 3). ' <br> ';
?>
The instance code is as follows:
Copy Code code as follows:
<?php
$str = ' HTTP://WWW.JB51.NET Cloud Habitat Community _ Script Programming Introductory Tutorial _ Script Design ac _ character occurrences ';
Echo Substr_count ($str, ' W '). ' <br/> ';
Echo Substr_count ($str, ' t '). ' <br/> ';
Echo Substr_count ($str, ' cloud-dwelling community ');
?>
The output results are:
3
3
1
And then share some string lookup functions:
strstr-the first occurrence of a lookup string
Stristr strstr case-insensitive version
Strpos-Find the position where the string first appears
String substr (string $string, int $start [, int $length])
String STRRCHR (String $haystack, mixed $needle)
Strripos-Calculates where the specified string last appears in the target string (case-insensitive)
Stripos-Find the position of the first occurrence of the string (case-insensitive)
Strrpos-Calculates where the specified string last appears in the target string
I hope this article will help you with your PHP program design.