【PHP】preg_replace( )
preg_replace — 执行一个正则表达式的搜索和替换
mixed preg_replace ( mixed $pattern
, mixed $replacement
, mixed $subject
[, int $limit
= -1[, int &$count
]] )
代码:
<?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern, $replacement, $string); ?>
显示结果:
April1,2003