当前位置:主页 > 查看内容

php正则之函数 preg_replace()参数说明

发布时间:2021-07-25 00:00| 位朋友查看

简介:preg_replace 字符串比对解析并取代。 语法:mixedpreg_replace(mixedpattern,mixedreplacement,mixedsubject); 返回值:混合类型资料 函数种类:资料处理 内容说明 本函数以pattern的规则来解析比对字符串subject,欲取而代之的字符串为参数replacement。返回……
preg_replace
字符串比对解析并取代。 
语法: mixed preg_replace(mixed pattern, mixed replacement, mixed subject); 
返回值: 混合类型资料 
函数种类: 资料处理 
内容说明 
本函数以 pattern 的规则来解析比对字符串 subject,欲取而代之的字符串为参数 replacement。返回值为混合类型资料,为取代后的字符串结果。 
使用范例 
下例返回值为 $startDate = 6/19/1969
复制代码 代码如下:

<?php 
$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"); 
?>  

原文链接:https://m.jb51.net/article/8675.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:关于preg_replace函数的问题讲解 下一篇:没有了

推荐图文


随机推荐