html meta tag parse 함수
기본설명에 있는것을 가져와 테스트만 한것인데 og 태그까지 문제 없이 잘 가져 옵니다.
function getMetaTags($str)
{
$pattern = '
~<\s*meta\s
# using lookahead to capture type to $1
(?=[^>]*?
\b(?:name|property|http-equiv)\s*=\s*
(?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
)
# capture content to $2
[^>]*?\bcontent\s*=\s*
(?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
[^>]*>
~ix';
if(preg_match_all($pattern, $str, $out))
return array_combine($out[1], $out[2]);
return array();
}
$meta_tags = getMetaTags($html_view);
관련링크