Original: PHP 18:data_valid_fns.php to see Regular expressions
This chapter describes the regular expressions.
Let's take a look at Data_valid_fns.php's code.
1<?PHP
2
3functionFilled_out ($form _vars)
4{
5 //test, each variable have a value
6 foreach ($form _vars as $key = $value)
7 {
8 if (!isset($key) || ($value == "'))
9 return false;
Ten }
One return true;
A}
-
- functionValid_email ($address)
the{
- //Check an E- mail address is possibly valid
- if (Ereg('^[a-za-z0-9_\.\-][email protected][a-za-z0-9\-]+\. [A-za-z0-9\-\.] +$', $address))
- return true;
+ Else
- return false;
+}
A
at ?>
-A brief introduction.
Filled_out ($form _vars) To verify the validity of the input.
Valid_email($address)Verify the validity of the email. It is done through regular expressions.
This chapter describes the regular expressions in detail.
PHP supports POSIX-extended regular expressions, and also supports regular expressions that are compatible with Perl syntax.
If you are not sure about regular expressions, see syntax for regular expressions.
Here we describe the following 2 formats of regular expressions
1 POSIX regular expression functions
In order to use this feature, you first need to configure PHP so that it supports it. If installed under Windows, it will be configured automatically. However, under other operating systems, manual configuration is required.
To activate the support for RegExp, add it when you configure PHP--with-regex[=TYPE]。 TYPE can be one of System,apache or PHP. PHP is used by default.
The supported functions are:
- Ereg_replace--Regular expression substitution
- Ereg--Regular expression matching
- Eregi_replace--case-insensitive regular expression substitution
- Eregi--case-insensitive regular expression matching
- Split--Splits a string into an array with regular expressions
- Spliti--separating strings into arrays with regular expressions that are case insensitive
- Sql_regcase-generates a regular expression for a match that is not size-sensitive
2 Perl-compatible regular expression functions
- Preg_grep--Returns the array unit that matches the pattern
- Preg_match_all--Global regular expression matching
- Preg_match--Perform regular expression matching
- Preg_quote--Escaping regular expression characters
- Preg_replace_callback--Perform a search and replace of regular expressions with callback functions
- Preg_replace--Perform search and replace of regular expressions
- Preg_split--splitting a string with regular expressions
PHP 18:data_valid_fns.php See Regular expressions