PHP code example of dlindberg / dom-document-factory

1. Go to this page and download the library: Download dlindberg/dom-document-factory 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/ */

    

dlindberg / dom-document-factory example snippets


$DOMElement = $docfactory($html);
echo $docfactory->stringify($DOMElement->firstChild);
 
echo $docfactory->stringify($DOMElement);

echo \implode(\PHP_EOL, $docfactory->stringifyFromList($DOMElement));

$DOMDocumentFactoryConfig = new DOMDocumentFactoryConfig(array $settings = [], \HTMLPurifier $inputPurifier = null, \HTMLPurifier $outputPurifier = null);

$DOMDocumentFactoryConfig->setInputPurifier(\HTMLPurifier $purifier);
$DOMDocumentFactoryConfig->setOutputPurifier(\HTMLPurifier $purifier);
$DOMDocumentFactoryConfig->version = '1.0';

$settings = [
    'version'             => '1.0',
    'encoding'            => 'UTF-8',
    'recover'             => true,
    'preserveWhiteSpace'  => false,
    'formatOutput'        => true,
    'DOMOptions'          => LIBXML_NOERROR | LIBXML_NOWARNING,
];

$node = DOMDocumentFactory::getDomNode(string $blob, DOMDocumentFactoryConfig $config = null);

$string = DOMDocumentFactory::stringifyNode(\DOMNode $node, DOMDocumentFactoryConfig $config = null);

$array = DOMDocumentFactory::stringifyNodeList(\DOMNodeList $nodes, DOMDocumentFactoryConfig $config = null);
 php
$html = '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'; // Etc. Etc.

$docFactory = new dlindberg\DOMDocumentFactory();

$DOMNode = $docfactory($html);

/* Do something with your DOMNodes */

echo $docFactory->stringify($DOMNode->firstChild);
html
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>In vel nibh eget turpis sagittis posuere ut vitae purus.<p>
<p>Donec in libero mauris. Aenean eu consectetur tortor.</p>
<p>Sed dolor neque, maximus et est eu, ultricies interdum libero.</p>
<p>Cras sed feugiat ante. Suspendisse ultrices eros at arcu feugiat dictum.</p>
html
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>In vel nibh eget turpis sagittis posuere ut vitae purus.<p>
<p>Donec in libero mauris. Aenean eu consectetur tortor.</p>
<p>Sed dolor neque, maximus et est eu, ultricies interdum libero.</p>
<p>Cras sed feugiat ante. Suspendisse ultrices eros at arcu feugiat dictum.</p>
</body>