如何在此处添加OR以使meta
与name
和property
匹配$html = '<meta name="title" content="title here..">
<meta name="keywords" content="keywords here..">
<meta property="og:title" content="og title here..">'
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $html, $match);
Array
(
[0] => Array
(
[0] => <meta name="title" content="title here..">
[1] => <meta name="keywords" content="keywords here..">
// [2] <meta property="og:title" content="og title here..">
)
[1] => Array
(
[0] => title
[1] => keywords
// [2] => og:title
)
[2] => Array
(
[0] => title here..
[1] => keywords here..
// [2] => og title here..
)
)
输出
{{1}}
答案 0 :(得分:0)
从@ chris85建议的链接中了解到,(name|property)
将会这样做。我的坏!
preg_match_all('/<[\s]*meta[\s]*(name|property)="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $html, $match);