我们在日常php开发中,有时需要正则匹配某个html标签之间的内容,这里记录一下php方法
/** * @param $string 需要匹配的字符串 * @param $tag html标签 */ function getTagValue($string, $tag){ $pattern = "/<{$tag}>(.*?)</{$tag}>/s"; preg_match_all($pattern, $string, $matches); return isset($matches[1]) ? $matches[1] : ''; }