preg_match 元名称或 属性

preg_match meta name OR property

如何在此处实现 OR 以匹配 metanameproperty

$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..
        )

)

从@chris85 建议的 link 中了解到,(name|property) 将执行此操作。我的错!

preg_match_all('/<[\s]*meta[\s]*(name|property)="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $html, $match);