PHP code example of panakour / phpdom

1. Go to this page and download the library: Download panakour/phpdom 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/ */

    

panakour / phpdom example snippets


$dom = new Dom('<html><body><p>Hello, World!</p></body></html>');

$images = $dom->getNodeList('img');

$imgSrc = $dom->getAttributesValue('img', 'src');

$dom->replaceAttributes('img', [
    ['src' => 'new-src.jpg', 'alt' => 'New image']
]);

$dom->removeElementsAndItsContent(['img']);