php100学习记录39

下面是学习代码,点击下载.

<?php
$pattern="/{(.*)}/U"; //U防止贪婪匹配
$subject="google is{title} a search{author} engine{con}";
 
preg_match_all($pattern,$subject,$arr);
print_r($arr); //匹配的结果是二位数组
 
?>
<br>
 
 
<?php
$pattern=array("/{title}/","/{author}/","/{con}/");
$replacement=array("标题","作者","内容");
$subject="google is{title} a search{author} engine{con}";
 
echo preg_replace($pattern, $replacement, $subject); //替换
?>
<br>
 
 
<?php
$pattern="/(a)/ie";
$re="qq";
$subject="google is a search engine";
 
echo preg_replace($pattern,"md5(\\1)",$subject,1);//对替换结果运算
?>
<br>
<br>
 
<?php 
$pattern="/[,.]/i";
$subject="sss.dada,fdfd.dasdsad,AS";
 
$arr=preg_split($pattern,$subject,3); //分割函数
print_r($arr);
?>

Related posts:

Leave a Reply

Your email address will not be published.