PHP Classes

File: example/example_extract_meta_tags.php

Recommend this page to a friend!
  Classes of Lars Moelleken   Simple HTML DOM   example/example_extract_meta_tags.php   Download  
File: example/example_extract_meta_tags.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple HTML DOM
Manipulate HTML elements using DOMDocument
Author: By
Last change: Update of example/example_extract_meta_tags.php
Date: 1 year ago
Size: 928 bytes
 

Contents

Class file image Download
<?php

use voku\helper\HtmlDomParser;

require_once
'../vendor/autoload.php';

$templateHtml = '
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="description" content="Free Web tutorials">
  <meta name="keywords" content="HTML,CSS,XML,JavaScript">
  <meta name="author" content="Lars Moelleken">
</head>
<body>

<p>All meta information goes in the head section...</p>

</body>
</html>
'
;

$htmlTmp = HtmlDomParser::str_get_html($templateHtml);
foreach (
$htmlTmp->find('meta') as $meta) {
    if (
$meta->hasAttribute('content')) {
       
$meta_data[$meta->getAttribute('name')][] = $meta->getAttribute('content');
    }
}

// dump contents
/** @noinspection ForgottenDebugOutputInspection */
var_export($meta_data, false);

/*
[
    'description' => [
        'Free Web tutorials',
    ],
    'keywords' => [
        'HTML,CSS,XML,JavaScript',
    ],
    'author' => [
        'Lars Moelleken',
    ],
]
 */