답변 2개
채택된 답변
+20 포인트
네 할수 있습니다.
아래는 URL 을 통한 메타태그 파싱 예제 입니다.
Copy
<?php
if (isset($_GET['url'])) {
$url = 'https://naver.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$metaTags = $dom->getElementsByTagName('meta');
$ogData = [];
foreach ($metaTags as $meta) {
if ($meta->hasAttribute('property') && strpos($meta->getAttribute('property'), 'og:') === 0) {
$ogData[$meta->getAttribute('property')] = $meta->getAttribute('content');
}
}
header('Content-Type: application/json');
echo json_encode($ogData); // 메타태그 정보 출력
} else {
echo json_encode(['error' => 'URL 정보가 올바르지 않음']);
}
?>
답변을 작성하려면 로그인이 필요합니다.