- 论坛徽章:
- 0
|
<?php
$str = '<meta content="整形" name="keywords">';
$regex_l = "/<meta\s+[^>]*name[=\s]+([\"']?)keywords?\\1\s+[^>]*content[=\s]+([\"']?)([^\\2]*?)\\2[^>]*\/?>/ismu";
if ( preg_match( $regex_l, $str, $matches ) ) {
$sKeywords = $matches[3];
} else {
$regex_r = "/<meta\s+[^>]*content[=\s]+([\"']?)([^>\\1]*?)\\1\s*[^>]*name[=\s]+([\"']?)keywords?\\3[^>]*\/?>/isum";
if ( preg_match( $regex_r, $str , $matches ) ) {
$sKeywords = $matches[2];
}
}
echo $sKeywords;
?>
原始代码在这里运行是没问题的
但是我想匹配 $str ='<meta content=整形 name=keywords>';
就不行了,请各位帮忙看一下,在线等
匹配 包含content='值' content="值" content=值
的三种情况
[ 本帖最后由 workingbeijing 于 2009-12-23 14:57 编辑 ] |
|