URLs get_meta_tags
(PHP 4, PHP 5, PHP 7, PHP 8)
get_meta_tags — 파일에서 모든 메타 태그 콘텐츠 속성을 추출하고 배열을 반환합니다.
설명
get_meta_tags(string $filename
, bool $use_include_path
= false
): array|false
filename
을 열고 파일의 <meta> 태그에 대해 한 줄씩 구문 분석합니다. 구문 분석은 </head>에서 멈춥니다.
매개변수
filename
- HTML 파일의 경로(문자열). 로컬 파일 또는 URL일 수 있습니다.
예제 #1 get_meta_tags()가 구문 분석하는 것
<meta name="author" content="name"> <meta name="keywords" content="php documentation"> <meta name="DESCRIPTION" content="a php manual"> <meta name="geo.position" content="49.33;-86.59"> </head> <!-- parsing stops here -->
use_include_path
use_include_path
를true
로 설정하면 PHP가 include_path 지시문에 따라 표준 포함 경로를 따라 파일을 열려고 합니다. 이것은 URL이 아닌 로컬 파일에 사용됩니다.
반환 값
모든 구문 분석된 메타 태그가 포함된 배열을 반환합니다.
name 속성의 값은 키가 되고 content 속성의 값은 반환된 배열의 값이 되므로 표준 배열 함수를 사용하여 쉽게 탐색하거나 단일 값에 액세스할 수 있습니다. name 속성 값의 특수 문자는 '_'로 대체되고, 나머지는 소문자로 변환됩니다. 두 메타 태그의 이름이 같으면 마지막 메타 태그만 반환됩니다.
실패 시 false
를 반환합니다.
Examples
예제 #2 get_meta_tags()가 반환하는 것
<?php
// Assuming the above tags are at www.example.com
$tags = get_meta_tags('http://www.example.com/');
// Notice how the keys are all lowercase now, and
// how . was replaced by _ in the key.
echo $tags['author']; // name
echo $tags['keywords']; // php documentation
echo $tags['description']; // a php manual
echo $tags['geo_position']; // 49.33;-86.59
?>
메모
메모: 이름 속성이 있는 메타 태그만 구문 분석됩니다. 따옴표는 필요하지 않습니다.
기타
- htmlentities() - 적용 가능한 모든 문자를 HTML 엔터티로 변환
- urlencode() - URL 인코딩 문자열