匹配出需要的字符串
preg_match($pattern, $str, $matchs);
$pattern 正则表达式
$str 要处理的字符串
$matchs 匹配出来的结果, $matchs[0]是匹配到的字符串, $matchs[1]是匹配到结果
// preg_match只会匹配出一个结果,如果有多个匹配则会匹配最外层的
全量匹配
preg_match_all();
$url = “<b>example: </b><div align=left>this is a test</div>”
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", $url, $matches);
$matches[1]的结果为:
array ( 0 => 'example: ', 1 => ‘this is a test’)
匹配出了所有的结果
正则替换
preg_replace($pattern, $newChar, $str)