2017 © Pedro Peláez
 

library domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

image

duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  • Tuesday, July 3, 2018
  • by duncan3dc
  • Repository
  • 4 Watchers
  • 3 Stars
  • 103,039 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 19 Versions
  • 5 % Grown

The README.md

domparser

Wrappers for the PHP DOMDocument class to provide extra functionality for html/xml parsing, (*1)

release build coverage, (*2)

Constructor Arguments

There are 2 constructors available, one for the HtmlParser class and one for the XmlParser class, they both work in the same way. * Only 1 parameter is available, which should be passed as a string, and contain the content to parse (xml/html) * Warnings are captured during the loading of the content using libxml_use_internal_errors() and libxml_get_errors(), these are available from the errors property after the class has been initiated, (*3)

Public Properties

  • html/xml (string) - Depending on which class was used one of these properties will be present and contain the content used for parsing
  • errors (array) - If any errors were encountered during parsing they will be in this array (see [Constructor Arguments])
  • dom (DOMDocument) - This is the internal instance of the DOMDocument class used
  • mode (string) - Indicates whether the parser is operating in html or xml mode

Public Methods

  • getTags(string $tagName): array - Similar to DOMDocument::getElementsByTagName() except a standard array is returned.
    Alias: getElementsByTagName()
  • getTag(string $tagName): Element - Similar to getTags() but will return the first element matched, instead of an array of elements.
    Alias: getElementByTagName()
  • getElementsByClassName(mixed $className): array - Matches elements that have a class attribute that matches the string parameter.
    If you want to find elements with multiple classes, pass the $className as an array of classes, and only elements that have all classes will be returned
  • getElementByClassName(mixed $className): Element - Similar to getElementsByClassName() except this will return the first element matched
  • output(): string - Returns the xml/html repesented by the receiver, formatted using DOMDocument::formatOutput
  • xpath(string $path): array - Returns an array of elements matching the $path

Dom Elements

All of the methods that return elements return them as instances of the Element class, this acts similarly to the standard DOMElement class, except it has all of the above methods available, and the nodeValue property has leading and trailing whitespace removed using trim(), (*4)

Examples

The parser classes use a namespace of duncan3dc\Dom, (*5)

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";

duncan3dc/domparser for enterprise

Available as part of the Tidelift Subscription, (*6)

The maintainers of duncan3dc/domparser and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more., (*7)

The Versions

03/07 2018

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

  • ext-dom *
  • ext-libxml *
  • php ^7.1

 

The Development Requires

parser xml html writer generation parsing domdocument

03/07 2018

dev-master

9999999-dev https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

  • ext-dom *
  • ext-libxml *
  • php ^7.1

 

The Development Requires

parser xml html writer generation parsing domdocument

05/11 2017

1.5.0

1.5.0.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

  • ext-curl *
  • ext-dom *
  • ext-libxml *
  • php ^5.6|^7.0

 

The Development Requires

parser xml html writer generation parsing domdocument

09/09 2015

1.4.1

1.4.1.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

  • ext-curl *
  • ext-dom *
  • ext-libxml *
  • php >=5.5.0

 

The Development Requires

parser xml html writer generation parsing domdocument

29/08 2015

1.4.0

1.4.0.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

  • ext-curl *
  • ext-dom *
  • ext-libxml *
  • php >=5.5.0

 

The Development Requires

parser xml html writer generation parsing domdocument

18/04 2015

1.3.7

1.3.7.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html writer generation parsing domdocument

17/03 2015

1.3.5

1.3.5.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html writer generation parsing domdocument

22/02 2015

1.3.4

1.3.4.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

31/12 2014

1.3.3

1.3.3.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

07/11 2014

1.3.2

1.3.2.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

12/09 2014

1.3.1

1.3.1.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

24/08 2014

1.3.0

1.3.0.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

24/06 2014

1.2.0

1.2.0.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

11/06 2014

1.1.4

1.1.4.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

05/06 2014

1.1.3

1.1.3.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

01/06 2014

1.1.2

1.1.2.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

01/06 2014

1.1.1

1.1.1.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

31/05 2014

1.1.0

1.1.0.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

 

parser xml html domdocument

31/05 2014

1.0.0

1.0.0.0 https://github.com/duncan3dc/domparser

Wrappers for the standard DOMDocument class to provide extra functionality for html/xml parsing

  Sources   Download

Apache-2.0

The Requires

  • ext-curl *
  • ext-dom *
  • ext-libxml *
  • php >=5.4.0

 

parser xml html domdocument