正则表达式主要有替换、匹配、分割。下面是演示代码:
//正则替换代码
// $str="标题 {title}<br>作者 {author}<br>书名 {bookname}";
// $mode=array("/{title}/","/{author}/","/{bookname}/");
// $str2=array("正则替换","张威","Php100");
// echo str_replace("title","标题",$str);
// echo preg_replace($mode,$str2,$str);
//正则替换修正符e
// $str="h a h a";
// $mode="/(a)/e";
//
// echo preg_replace($mode,"md5(\\1)",$str);
//正则分割explode
$str2="hhh,hhig.sghsi%gdsg";
$mode="/[,.%]/";
//正则分割
$str= preg_split($mode,$str2);
// print_r ($str);
//echo $str[0];
foreach($str as $key=>$value){
echo $str[$key]."<br>";
}