Home> php教程> php手册> body text

php preg_match正则表达式函数实例,phppregmatch函数

WBOY
Release: 2016-06-13 08:43:16
Original
1354 people have browsed it

php preg_match正则表达式函数实例,phppregmatch函数

正则表达式几乎在所有编程语言里面都会用到,本实例介绍php中正则表达式preg_match函数的应用。

preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 。
preg_match() 匹配成功一次后就会停止匹配,如果要实现全部结果的匹配,则需使用 preg_match_all() 函数。

语法:

preg_match (pattern , subject, matches)

参数 描述
pattern 正则表达式
subject 需要匹配检索的对象
matches 可选,存储匹配结果的数组


实例:
此实例匹配大写字母后面带有.和空格的字符串,只能匹配到J. ,因为preg_match() 匹配成功一次后就会停止匹配,后面不会再匹配了。

php $str="Daniel J. Gross Catholic High School A. is a faith and family based community committed to developing Christian leaders through educational excellence in the Marianist tradition."; if(preg_match("/[A-Z]. /",$str,$matches)){ print_r($matches); } ?>
Copy after login

输出结果:

Array ( [0] => J. )
Copy after login

原文地址:http://www.manongjc.com/article/52.html

相关阅读:

php正则表达式函数使用实例

php preg_match函数和php preg_match_al函数l实例,方法,例子

php preg_match_all()函数使用实例

php preg_match正则表达式函数实例

source:php.cn
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!