当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP正则相关的几个preg函数

PHP
PHP新手总结的PHP基础知识
php实现gb2312和unicode间编码转换
用php语言实现数据库连接详细代码介绍
详细解析 PHP 向 MySQL 发送数据过程
利用PHP V5开发多任务应用程序
详细讲解PHP中缓存技术的应用
php escapeshellcmd多字节编码漏洞
《PHP设计模式介绍》导言
《PHP设计模式介绍》第一章 编程惯用法
《PHP设计模式介绍》第二章 值对象模式
《PHP设计模式介绍》第三章 工厂模式
《PHP设计模式介绍》第四章 单件模式
《PHP设计模式介绍》第五章 注册模式
《PHP设计模式介绍》第六章 伪对象模式
《PHP设计模式介绍》第七章 策略模式
《PHP设计模式介绍》第八章 迭代器模式
《PHP设计模式介绍》第九章 观测模式
《PHP设计模式介绍》第十章 规范模式
《PHP设计模式介绍》第十一章 代理模式
《PHP设计模式介绍》第十二章 装饰器模式

PHP正则相关的几个preg函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 231 ::
收藏到网摘: n/a

, this is a test

 

preg_replace

字符串比对解析并取代。

语法: mixed preg_replace(mixed pattern, mixed replacement, mixed subject);

返回值: 混合类型资料

函数种类: 资料处理

内容说明: 本函数以 pattern 的规则来解析比对字符串 subject,欲取而代之的字符串为参数 replacement。返回值为混合类型资料,为取代后的字符串结果。

使用范例

下例返回值为 $startDate = 6/19/1969

$patterns = array("/(19|20\d{2})-(\d{1,2})-(\d{1,2})/", "/^\s*{(\w+)}\s*=/");

$replace = array("\\3/\\4/\\1", "$\\1 =");

print preg_replace($patterns, $replace, "{startDate} = 1969-6-19");

?>

preg_split

将字符串依指定的规则切开。

语法: array preg_split(string pattern, string subject, int [limit]);

返回值: 数组

函数种类: 资料处理

内容说明: 本函数可将字符串依指定的规则分开。切开后的返回值为数组变量。参数 pattern 为指定的规则字符串、参数 subject 则为待处理的字符串、参数 limit 可省略,表示欲处理的最多合乎值。