";
}
// Load HTML content into DOMDocument
$doc = new DOMDocument();
libxml_use_internal_errors(true); // Ignore HTML warnings
$doc->loadHTML($htmlContent);
libxml_clear_errors();
// Look for tag
$metaTags = $doc->getElementsByTagName('meta');
$metaData = [];
foreach ($metaTags as $meta) {
$name = $meta->getAttribute('name') ?: $meta->getAttribute('property') ?: $meta->getAttribute('itemprop');
$content = $meta->getAttribute('content');
if ($name && $content) {
if (!array_key_exists($name, $metaData)) {
$metaData[$name] = $content;
} elseif (!in_array($content, explode(' ', $metaData[$name]))) {
//$metaData["item-{$name}"] = $content;
$metaData[$name] .= ' ' . $content;
}
}
}
if ($metaData) {
// Define names, emoji icons, and descriptions for common meta tags
$metaFriendlyNames = [
// HTML Standard Meta Tags
'title' => ['name' => 'Page Title', 'icon' => 'đ', 'description' => 'The title of the webpage, shown on the browser tab.'],
'description' => ['name' => 'Description', 'icon' => 'đ', 'description' => 'A short summary of the page content.'],
'keywords' => ['name' => 'Keywords', 'icon' => 'đ', 'description' => 'A list of keywords relevant to the page, used for SEO.'],
'author' => ['name' => 'Author', 'icon' => 'âī¸', 'description' => 'The author of the webpage.'],
'robots' => ['name' => 'Robots', 'icon' => 'đ¤', 'description' => 'Instructions for search engines on whether to index the page.'],
'viewport' => ['name' => 'Viewport', 'icon' => 'đą', 'description' => 'Defines the visible area of the webpage on different devices.'],
'charset' => ['name' => 'Charset', 'icon' => 'đ ', 'description' => 'Character encoding used by the page.'],
// Open Graph Meta Tags
'og:title' => ['name' => 'OG Title', 'icon' => 'đ', 'description' => 'The title of the page when shared on social platforms.'],
'og:description' => ['name' => 'OG Description', 'icon' => 'đ', 'description' => 'A brief description for social sharing.'],
'og:image' => ['name' => 'OG Image', 'icon' => 'đŧī¸', 'description' => 'The image displayed when the page is shared.'],
'og:url' => ['name' => 'OG URL', 'icon' => 'đ', 'description' => 'Canonical URL of the page being shared.'],
'og:type' => ['name' => 'OG Type', 'icon' => 'đ', 'description' => 'The type of content (e.g., article, website, video).'],
'og:site_name' => ['name' => 'OG Site Name', 'icon' => 'đ ', 'description' => 'The name of the website.'],
'og:locale' => ['name' => 'OG Locale', 'icon' => 'đ', 'description' => 'The locale of the page (e.g., en_US).'],
// Twitter Meta Tags
'twitter:title' => ['name' => 'Twitter Title', 'icon' => 'đĻ', 'description' => 'The title of the page when shared on Twitter.'],
'twitter:description' => ['name' => 'Twitter Description', 'icon' => 'đĻđ', 'description' => 'A brief description for Twitter sharing.'],
'twitter:image' => ['name' => 'Twitter Image', 'icon' => 'đĻđŧī¸', 'description' => 'The image displayed when the page is shared on Twitter.'],
'twitter:card' => ['name' => 'Twitter Card', 'icon' => 'đĻđ', 'description' => 'The type of Twitter card to display (e.g., summary, player).'],
// Other common meta tags
'canonical' => ['name' => 'Canonical URL', 'icon' => 'đ', 'description' => 'The preferred URL for the page, used to avoid duplicate content.'],
];
// Display meta tags in table format with names, icons, and raw names
echo "
";
echo "
Meta Tag
Value
";
foreach ($metaData as $key => $value) {
$friendlyName = $metaFriendlyNames[$key]['name'] ?? ''; // Use friendly name if available
$icon = $metaFriendlyNames[$key]['icon'] ?? 'âšī¸'; // Use icon if available
// Update table row to include icon, friendly name, and raw name
echo "
$icon{$friendlyName} ($key)
$value
";
}
echo "
";
} else {
echo "
No meta tags found on the provided URL.
";
}
$linkTags = extractLinkTags($htmlContent);
if ($linkTags) {
// Display the table with elements
echo "
";
echo "
Link Reference (rel)
Link Href
";
foreach ($linkTags as $key => $value) {
echo "
{$key}
{$value}
";
}
echo "
";
}
// Extract important meta information for social media previews
$title = $metaData['og:title'] ?? $metaData['twitter:title'] ?? "Untitled";
$description = $metaData['og:description'] ?? $metaData['twitter:description'] ?? "No description available.";
$image = $metaData['og:image'] ?? $metaData['twitter:image'] ?? "";
$ogType = $metaData['og:type'] ?? '';
// Only show video if `og:type` is not `video.other`
if ($ogType !== 'video.other') {
$video = $metaData['og:video'] ?? $metaData['twitter:player'] ?? "";
} else {
$video = null; // Ignore video.other type
}
echo "
";
// Display video if present and og:type is allowed
if ($video) {
echo "";
}
// Display image if available
elseif ($image) {
echo "";
}
// Graceful fallback to placeholder
else {
echo "";
}
// Display title and description
echo "