[php] preg_match_all(); //匹配(采集)

$mode = “/{(.*)}/U”; //防止贪婪匹配

$source = “dsf{title}fdsa{author}rdgf{content}”;

if(preg_match_all($mode, $source, $arr)) print_r ($arr); else echo “失败”;

preg_replace(); //替换

$mode = array(“/{title}/”, “/{author}/”, “/{content}/”); $met = array(“PHP中文”, “xjh”, “学习门户”); $source = “标题:{title}
作者:{author}
内容:{content}”;

//echo str_replace(“{title}”, “中文”, $source); echo preg_replace($mode, $met, $source);

$mode = “/([a-z])/ie”; $source = “123122a22453b453c”;

echo preg_replace($mode, “md5(\1)”, $source); //$source 后可选参数控制替换次数

preg_split(); //分割

$mode = “/[,.]/”;

$source = “123,122.a224,53b453c”;

$arr = preg_split($mode, $source); print_r($arr);

[/php]