Using preg_match(), we can complete the rule matching of strings. The preg_match() function returns 1 if a match is found, 0 otherwise. There is an optional third parameter that allows you to store the matched parts in an array. This feature can become very useful when validating data.
The code is as follows | Copy code | ||||||||||||||||||||||||||||||||||||
if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
}
preg_match($pattern,$string,$matcher) where $pattern corresponds to /^(http://)?([^/]+)/i, $string is http://www.php. net/index.html, $match is the matched result. If matches is provided, it will be populated with the results of the search. $matches[0] will contain text that matches the entire pattern, $matches[1] will contain text that matches the first captured subpattern in parentheses, and so on. $matches[0] will contain text that matches the entire pattern. Let’s use spring_r to print out the first $matches:
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628982.htmlTechArticleUsing preg_match(), we can complete the rule matching of strings. The preg_match() function returns 1 if a match is found, 0 otherwise. There is also an optional third parameter that allows...
Previous article:Detailed introduction to PHP flock file lock_PHP tutorial
Next article:PHP singleton mode study notes_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
When adding sublime3 to compile system php, use the PHP toolbox, cmd php -v is useless
From 1970-01-01 08:00:00
0
0
0
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|