The use of regular expressions in PHP gives us a new sense of reality, so how do we master such a powerful tool? Let's take a look at the early knowledge of PHP regular expression learning and hope to help you.
PHP is widely used in the background CGI development of the web, usually after the user data data to obtain a certain result, but if the user input data is incorrect, there will be problems, such as someone's birthday is "February 30"! What should I do to check whether the summer vacation is correct? The support of PHP regular expressions allows us to easily match data.
Some concepts related to PHP regular expressions:
In short, regular expressions are a powerful tool that can be used for pattern matching and substitution. Find traces of regular expressions in almost all software tools based on the Unix/linux system, such as Perl or PHP scripting languages. In addition, JavaScript, a client-side scripting language, also provides support for regular expressions, and now regular expressions have become a common concept and tool that is widely used by various technical staff.
On one of the Linux sites, "If you ask what Linux enthusiasts like best, he may answer regular expressions, and if you ask him what he fears most, he will say regular expressions in addition to the cumbersome installation configuration." "
As said above, the regular expression looks very complex, scary, most of the PHP beginners will skip here, continue the following learning, but the regular expression in PHP has the ability to use pattern matching to find a qualifying string, It is a pity to judge whether a string is eligible or to replace a string with a specified string, such as a strong function.
Basic syntax for PHP regular expressions:
A regular expression, divided into three parts: delimiters, expressions, and modifiers.
The delimiter can be any character other than a special character (such as "/!"). And so on), the commonly used delimiter is "/". Expressions are made up of special characters (see below for special characters) and non-special strings, such as "[a-z0-9_-]+@[a-z0-9_-.] + "can match a simple e-mail string. Modifier is used to turn on or off a function/mode. Here is an example of a complete regular expression:
- /hello.+?hello/is
The above regular expression "/" is the delimiter, between two "/" is an expression, the second "/" after the string "is" is the modifier.
If you have delimiters in an expression, you need to use the escape symbol "", such as "/hello.+?/hello/is". Escape symbols can also execute special characters in addition to delimiters, and all the special characters that are composed of letters need to be "" to escape, such as "D" for all numbers.
A little understanding of PHP regular expressions is introduced to you here, hoping to help you understand and master PHP regular expressions.
http://www.bkjia.com/PHPjc/446586.html www.bkjia.com true http://www.bkjia.com/PHPjc/446586.html techarticle The use of regular expressions in PHP gives us a new sense of reality, so how do we master such a powerful tool? Let's take a look at the regular expressions for PHP ...