php正则替换

$string = ‘April 15, 2003‘;
$pattern = ‘/(\w+) (\d+), (\d+)/i‘;
$replacement = ‘${1}1,\3‘;

//$replacement ‘${1}1,$3‘;

//$replacement ‘${1}1,{3}‘;

echo preg_replace($pattern, $replacement, $string);
echo ‘<br/>‘;
//-----------------------------


$string = ‘The quick brown fox jumped over the lazy dog.‘;
$patterns = array();
$patterns[0] = ‘/quick/‘;
$patterns[1] = ‘/brown/‘;
$patterns[2] = ‘/fox/‘;
$replacements = array();
$replacements[2] = ‘bear‘;
$replacements[1] = ‘black‘;
$replacements[0] = ‘slow‘;
echo preg_replace($patterns, $replacements, $string);

echo ‘<br/>‘;
//---------------------------------
    //$d = $db->select(‘select * from <{:task}> limit 2‘);
        self::$_sql = preg_replace(‘/<{:\s*(.*?)\s*}>/‘, $this->_prefix . ‘\1‘, $sql);
        $this->_res = mysql_query(self::$_sql, $this->_db);

本文出自 “惊鸿一羽” 博客,请务必保留此出处http://haocaige.blog.51cto.com/1319521/1622222

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。