加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php preg_match正则表达式函数实例

发布时间:2020-12-13 05:18:04 所属栏目:PHP教程 来源:网络整理
导读:preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 。 preg_match() 匹配成功一次后就会停止匹配,如果要实现全部结果的匹配,则需使用 preg_match_all() 函数。 语法: preg_match (pattern,subject,matches) 参数 描述 pattern 正则表达

preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 。


preg_match() 匹配成功一次后就会停止匹配,如果要实现全部结果的匹配,则需使用 preg_match_all() 函数。


语法:

preg_match (pattern,subject,matches)

参数

描述

pattern

正则表达式

subject

需要匹配检索的对象

matches

可选,存储匹配结果的数组


实例:


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


$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);

}

?>

输出结果:


Array ( [0] => J. )


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读