PHP code example of duncan3dc / domparser

1. Go to this page and download the library: Download duncan3dc/domparser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

duncan3dc / domparser example snippets


use duncan3dc\Dom\Html\Parser;
use duncan3dc\Dom\Xml\Parser;

$parser = new Parser(file_get_contents("http://example.com"));

echo "Page Title: " . $parser->getTag("title")->nodeValue . "\n";

$contentType = false;
$meta = $parser->getTags("meta");
foreach($meta as $element) {
	if($element->getAttribute("http-equiv") == "Content-type") {
		$contentType = $element->getAttribute("content");
	}
}
echo "Content Type: " . (($contentType) ?: "NOT FOUND") . "\n";