When learning PHP, you may encounter a PHP regular expression judgment problem. here we will introduce the solution to the PHP regular expression problem. here we will share it with you. In some query websites and search engines, it is often used to determine whether a string is a standard IP address. For example, in Baidu search for a... "> <LINKhref =" http://www.php100.com//statics/style/h
When learning PHP, you may encounter a PHP regular expression judgment problem. here we will introduce the solution to the PHP regular expression problem. here we will share it with you. In some query websites and search engines, it is often used to determine whether a string is a standard IP address.
For example, if you search for an IP address in Baidu, the information of the IP address is displayed, but the IP address that does not comply with the standard is not displayed. In this case, it is necessary to determine whether the string is a standard IP address. The most common method is to use a PHP regular expression. It is too simple to search for some regular expressions on the Internet to judge the IP address. some of them only judge that the IP field is not greater than 255. In fact, there are still a lot to be judged. for example, they can only be numbers and cannot be negative numbers, ". "Only 4 segments are separated. I 'd better organize a function that feels perfect. the code is as follows:
-
Functionis_ip ($ gonten ){
- $ Ip = explode (".", $ gonten );
- For ($ I = 0; $ I
- {
- If ($ ip [$ I]> 255 ){
- Return (0 );
- }
- }
- Returnereg ("^ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3} $ ", $ gonten );
- }
$ Gonten is the string to be queried. you can use is_ip ($ gonten) to determine the value. The return values are FALSE and TRUE.
1. the eregi statement is case insensitive.
-
If (eregi ("^ [a-zA-Z0-9] {8, 10} $", "999999999") echo "is eight to ten digits and letters ";
2. replace the ereg_replace of the text in case-sensitive mode
-
$ String = "Thisisatest ";
- // Replace is with was
- Echoereg_replace ("is", "was", $ string );
You can also use \ to reverse reference the character 0 in parentheses to indicate that all 1 represents the first matched string, and so on, a maximum of 9! The usage of eregi_replace in case-insensitive text is the same as that in the manual.
3. case-sensitive string partitioning into split statements of different elements
-
Print_r (split ("[\ n \ t]", "I love \ n Beijing \ t Tiananmen "));
Case insensitive: the spliti statement is used the same as above.
4. only the case-sensitive regular expression SQL _regcase is supported.
-
$ Name = "xuandun ";
- Echosql_regcase ($ name );