In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the example usage of PHP regular processing functions preg_match, preg_match_all, preg_replace and preg_split. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn the example usage of the PHP regular processing functions preg_match, preg_match_all, preg_replace and preg_split.
Let's take a look at some common regular expression processing functions.
1the preglossmatch () function.
The function preg_match () performs a regular expression match defined as follows:
Int preg_match (string $pattern, string $subject [, array & $matches [, int $flags = 0 [, int $offset = 0])
It is actually searching for parts of the subject that match pattern to save in the array matches. Take a look at the example:
The copy code is as follows:
In the above example, we use the pattern modifier e so that the strtoupper () function can be parsed as a string, which is what the pattern modifier e does! The parameters ${1} and\ 2 are submode 1 and submode 2, respectively. The purpose of the above example is to replace the matching subpatterns php and mysql in the string $string with uppercase letters!
4the prestressed split () function.
Preg_split executes a regular expression to separate strings. It is defined as follows:
Array preg_split (string $pattern, string $subject [, int $limit =-1 [, int $flags = 0]])
In fact, it splits the subject according to pattern and returns the split array. Among them, limit will limit the separation of the resulting substrings to a maximum of limit, and the last substring returned will contain all the remaining parts. A value of-1, 0 or null means "unlimited".
Let's look at an example:
The copy code is as follows:
In the above example, we used the constant PREG_SPLIT_DELIM_CAPTURE to set the return result to include submodes (if set to PREG_SPLIT_NO_EMPTY,preg_split () to enter the non-empty part after the return is separated). If we remove the parentheses from the regular expression in the above example, the results no longer include the two successful matching subpatterns, php and mysql.
At this point, I believe you have a deeper understanding of the example usage of the PHP regular processing functions preg_match, preg_match_all, preg_replace and preg_split, so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.