继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

php正则替换

繁星coding
关注TA
已关注
手记 205
粉丝 10
获赞 54

$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);


//---------------------------------

    if (preg_match('/^p-(\d+)$/', $segment3, $m)) {
            $page = intval($m[1]);
        }
        else if (preg_match('/^\d+$/', $segment3)) {
            $task_type = intval($segment3);
            if (preg_match('/^p-(\d+)$/', $setment4, $m2)) {
                $page = intval($m2[1]);
            }    
        }

  preg_match_all("/{([^\}\{\n]*)}/e",$contents , $source);
  echo   preg_replace("/{([^\}\{\n]*)}/e", " ", $contents);

  return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);



$str = "http://112.125.116.137:9012/llys//lldoctor";               
            $pattern = '/(http:\/\/[^\/]+\/)(.*)/i';
             preg_match($pattern,$str,$result);  
            echo "aaaaaa" ; dump($result);
            preg_match("/php/i", "PHP is the web scripting language of choice.",$result);
            echo "bbbb" ; dump( $result);
             preg_match('/http:\/\/[^\/]+\//i', $str ,$result);
            echo "bbbb" ; dump( $result);
            exit;
           echo  $this->serinfo ."|". U('Home/Public/psysSendMessages');

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP