2017 © Pedro Peláez
 

library pop-dom

Pop DOM Component for Pop PHP Framework

image

popphp/pop-dom

Pop DOM Component for Pop PHP Framework

  • Monday, January 29, 2018
  • by nicksagona
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,712 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 4 % Grown

The README.md

pop-dom

Build Status Coverage Status, (*1)

Join the chat at https://discord.gg/TZjgT74U7E, (*2)

Overview

pop-dom is a component for generating, rendering and parsing DOM documents and elements. With it, you can easily create or parse document nodes and their children and have control over node content and attributes., (*3)

pop-dom is a component of the Pop PHP Framework., (*4)

Top, (*5)

Install

Install pop-dom using Composer., (*6)

composer require popphp/pop-dom

Or, require it in your composer.json file, (*7)

"require": {
    "popphp/pop-dom" : "^4.0.5"
}

Top, (*8)

Quickstart

A simple DOM node fragment

use Pop\Dom\Child;

$div = new Child('div');
$h1  = new Child('h1', 'This is a header');
$p   = new Child('p');
$p->setNodeValue('This is a paragraph.');

$div->addChildren([$h1, $p]);

echo $div;
<div>
    <h1>This is a header</h1>
    <p class="paragraph">This is a paragraph.</p>
</div>

Building a full DOM document

use Pop\Dom\Document;
use Pop\Dom\Child;

// Title element
$title = new Child('title', 'This is the title');

// Meta tag
$meta = new Child('meta');
$meta->setAttributes([
    'http-equiv' => 'Content-Type',
    'content'    => 'text/html; charset=utf-8'
]);

// Head element
$head = new Child('head');
$head->addChildren([$title, $meta]);

// Some body elements
$h1 = new Child('h1', 'This is a header');
$p  = new Child('p', 'This is a paragraph.');

$div = new Child('div');
$div->setAttribute('id', 'content');
$div->addChildren([$h1, $p]);

// Body element
$body = new Child('body');
$body->addChild($div);

// Html element
$html = new Child('html');
$html->addChildren([$head, $body]);

// Create and render the DOM document with HTTP headers
$doc = new Document(Document::HTML, $html);
echo $doc;
<!DOCTYPE html>
<html>
    <head>
        <title>This is the title</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <div id="content">
            <h1>This is a header</h1>
            <p>This is a paragraph.</p>
        </div>
    </body>
</html>

Top, (*9)

Parsing

You can parse from a string of XML or HTML and it will return an object of Child elements that you can further manipulate or edit to then output:, (*10)

$html = <<<HTML
<html>
    <head>
        <title>Hello World Title</title>
    </head>
    <body>
        <h1 class="top-header" id="header">Hello World Header</h1>
        <p>How are <em>YOU</em> doing <strong><em>today</em></strong>???</p>
        <p class="special-p">Some <strong class="bold">more</strong> text.</p>
    </body>
</html>
HTML;

$doc = new Document(Document::HTML);
$doc->addChild(Child::parseString($html));
echo $doc;

And you can parse from a file as well:, (*11)

$children = Child::parseFile('index.html');

Top, (*12)

The Versions

29/01 2018

v2.x-dev

2.9999999.9999999.9999999-dev http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

29/01 2018

dev-master

9999999-dev http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

29/01 2018

dev-v3-dev

dev-v3-dev http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

29/01 2018

3.2.4

3.2.4.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

22/11 2017

3.2.3

3.2.3.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

16/11 2017

3.2.2

3.2.2.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

10/11 2017

3.2.1

3.2.1.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

09/11 2017

3.2.0

3.2.0.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

09/10 2017

3.1.0

3.1.0.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

27/02 2017

3.0.0

3.0.0.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.6.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

01/07 2016

2.1.0

2.1.0.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

10/05 2016

2.0.0p2

2.0.0.0-patch2 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

19/02 2016

2.0.0p1

2.0.0.0-patch1 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation

22/07 2015

2.0.0

2.0.0.0 http://www.popphp.org/

Pop DOM Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php dom pop pop php document object model dom generation dom manipulation