热门IT资讯网

php正则替换

发表于:2024-11-26 作者:热门IT资讯网编辑
编辑最后更新 2024年11月26日,$string = 'April 15, 2003';$pattern = '/(\w+) (\d+), (\d+)/i';$replacement = '${1}1,\3';//$replaceme

$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 '
';
//-----------------------------


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

0