php function Preg_match () prototype: int Preg_match (String $pattern, String $content [, array $matches])
The PHP function Preg_match () searches the $content string for content that matches the regular expression given by the $pattern. If $matches is provided, the matching result is placed in it. $matches [0] will contain text that matches the entire pattern, $matches [1] will contain the first captured content that matches the pattern cell in parentheses, and so on. This function only matches once, and eventually returns the number of matches for 0 or 1. Code 6.1 shows a code example for the Preg_match () function.
Code 6.1 date-time matching
- A matching string is required. The DATE function returns the current time
- $ content = "Current date and time is" .
Date ("Y-m-d h:i a"). ",
- We are learning PHP together. ";
- Use the usual method to match the time
- if (Preg_match ("/d{4}-d{2}-d{2} d{2}
:D {2} [ap]m/], $content, $m))
- {
- echo "matches the time:". $m [0]. "N";
- }
- Because the pattern of time is obvious, it can be easily matched.
- if (Preg_match ("/([d-]{10}) ([D:]{5}
[ap]m)/", $content, $m))
- {
- echo "Current date is:" $m [1]. "N";
- echo "Current time is:". $m [2]. "N";
- }
- ?>
This is a simple dynamic text string matching instance. Assuming that the current system time is "August 17, 2006 13:25", the output will be as follows.
The time to match is: 2006-08-17 01:25 pm
The current date is: 2006-08-17
The current time is: 01:25 pm
The above is the PHP function Preg_match () of the specific function examples, I hope you can master.
http://www.bkjia.com/PHPjc/446252.html www.bkjia.com true http://www.bkjia.com/PHPjc/446252.html techarticle php function Preg_match () prototype: int Preg_match (String $pattern, String $content [, array $matches]) PHP function Preg_match () in $ The content string searches for regular expressions given with $pattern ...