The previous article introduced you to "What are the pattern modifiers in PHP? How are they used? (With detailed explanation)》, this article will continue to introduce to you and let’s talk about the regular expression functions in PHP? How to use it (with code)
Regular expression function
preg. grep() returns the array unit that matches the pattern ( One-dimensional array)
First, we first understand the array unit (preg_prep) that returns the pattern matching, and then we start writing parameters. The first parameter @param1 (pass in the regular expression to be matched formula); the second parameter @param2 (array to be matched); the third parameter @param3 (optional parameter);
We first define an array, $arr, and then we define the regular expression Formula $pattern, then output the result (result) of (preg_grep), and finally we print out $result; when we print the results, we find that we did not print out those pure letters,
Code running results:
Let’s continue to understand (the function that performs a regular match) preg_match. We define the regular expression $pattern,
The code running result:
The above code shows that if we want to do some queries or matching in the future, we just want to test whether there is what we want. If it is, it means success, and if it is not, it means failure.
Contrary to the function we mentioned above, there is also //preg_ match_ _all(), which performs regular matching to obtain all matching content. Copy the above code and add all after $result = preg_match to get $result = preg_match_all , the result of running the code is that all the results we input are output, and the result returns a two-dimensional array,
The result of running the code:
Recommended learning : "PHP Video Tutorial"
The above is the detailed content of What are regular expression functions in PHP? (detailed instructions for use). For more information, please follow other related articles on the PHP Chinese website!