Home > Backend Development > PHP Tutorial > php 正则中运用函数的方式

php 正则中运用函数的方式

WBOY
Release: 2016-06-13 13:15:43
Original
941 people have browsed it

php 正则中使用函数的方式

//正则案例:使用php函数来改变字符值 
$string = "April 15, 2003"; 
 
//注意:使用模式修正符 /e 其作用是将匹配结果用作表达式,须使用它才可以使用\\3这样模式变量 
$pattern = "/(\w+) (\d+), (\d+)/e"; 
 
// 此处的模式变量\\2将被strtoupper转换为大写字符 : 注意函数当中用单引号连接 '字符串'.函数('模式变量').'字符串' 
$replacement = "'\\2'.strtoupper('\\1').'1,\\3'"; 
 
$s = preg_replace($pattern, $replacement, $string); 
echo $s;//输出 15APRIL1,2003 
Copy after login
?
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template