教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php正则表达式 preg_replace替换 入门教程

php正则表达式 preg_replace替换 入门教程

发布时间:2016-10-26   编辑:jiaochengji.com
教程集为您提供php正则表达式 preg,replace替换 入门教程等资源,欢迎您收藏本站,我们将为您提供最新的php正则表达式 preg,replace替换 入门教程资源
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3401')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3401>$mode = "/^[a-z][-_.]?[a-zd]*@[a-z0-9] [.][a-z]{2,4}/i";
$str = "a12345@jjquerycn.cn";
echo $str.'<hr>';
if(preg_match($mode, $str, $arr)){
echo 'succeed -- <font color=red>'.$arr[0];
}else{
echo 'failed';
}

 


d 包含所有数字[0-9]
d 除所有数字外[^0-9]
w 包含所有英文字符[a-za-z_0-9]
w 除所有英文字符外[^a-za-z_0-9]
s 包含空白区域如回车、换行、分页等 [fnr]


preg_match_all ( string pattern, string subject, array matches [, int flags] )
截取比较详细的内容,采集网页,分析文本

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7855')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7855>preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )
preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )


提示 1、替换内容可以是一个正则也可以是数组正则
2、替换内容可以通过修正符e来解决替换执行内容

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4694')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4694>preg_split ( string pattern, string subject [, int limit [, int flags]] )

 

您可能感兴趣的文章:
php正则表达式是什么?(代码实例)
正则表达式处理函数 preg_match,preg_match_all
php正则表达式替换URL链接地址为指定url
PHP正则过滤文章中图片的方法
php怎么去除空白字符
使用正则表达式进行查找替换
php正则表达式 preg_replace替换 入门教程
适合入门的php基础系列教程
php 正则 ereg_replace替换
php实现特殊字符的替换操作

[关闭]
~ ~