通过一些易于使用的功能扩展 DOMDocument。

v1.1.0 2019-02-07 13:42 UTC

This package is auto-updated.

Last update: 2024-09-08 07:11:20 UTC


README

通过一些易于使用的功能扩展 DOMDocument。

安装

composer require quentinbuiteman/easy-dom

使用

use \EasyDOM\DOMDocument;

// Initliaze new DOMDocument with preserveWhiteSpace = false and formatOutput = true
$DOM = new DOMDocument();

/**
 * Example to create a new element
 *
 * First parameter determines which element to create
 * Second parameter is an array of attributes to use in element creation (optional)
 * Third parameter is the text for inside the element (optional)
 */
$atts = array('class' => 'text');
$p = $this->DOM->generateElement('p', $atts, 'This will be the text inside the paragraph.');
$this->DOM->appendChild($p);

/**
 * Example to add nodes to an element based on a HTML string
 */
$html = '<p>This is a test HTML string.</p>';
$div = $this->DOM->createElement('div');
$div->addInnerHTML($html);