Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php parse html

$dom = new DOMDocument();
$dom->loadHTMLFile('path/to/htmlfile.html');    // or loadHTML($str)
$dom->load('path/to/xmlfile.xml');              // or loadXML($str)

$table = $dom->getElementById('mytable-id');    // DOMElement
$lines = $table->getElementsByTagName('tr');    // DOMNodeList
$links = $dom->getElementsByTagName('a');

$xpath = new DOMXpath($dom);
$tables = $xpath->query("//table[contains(@class,'mytables-class')]");
Comment

parsing HTML in php

<?php

require_once('simple_html_dom.php');

function getByClass($element, $class)
{
    $content= [];

    $html = 'index.html';

    $html_string = file_get_contents($html);

    $html = str_get_html($html_string);

    foreach ($html->find($element) as $element) {
        if ($element->class === $class) {
            array_push($heading, $element->innertext);
        }
    }

    print_r($content);
}

getByClass("h2", "main");
getByClass("p", "special");
Comment

PREVIOUS NEXT
Code Example
Php :: how to get meta information from pagination in laravel controller 
Php :: php exec get pid 
Php :: switch php versions 
Php :: php get 
Php :: unset php return array 
Php :: joomla get group id 
Php :: get joomla group ids 
Php :: update laravel 
Php :: create symfony 4 project 
Php :: laravel auth setup 
Php :: woocommerce product hooks 
Php :: print in file php 
Php :: php apply function to array elements 
Php :: php string random 
Php :: worpdress pods taxonomy get custom field 
Php :: datatable filters 
Php :: get file request in laravel 
Php :: Advanced Custom Fields get sub field image 
Php :: symfony messenger transport 
Php :: laravel crud generator 
Php :: php isset form submit 
Php :: how to get client ip address in php 
Php :: wordpress nav menu align right 
Php :: [ERROR] InvalidArgumentException: Wrong file in C:xampphtdocsmagento2.4libinternalMagentoFrameworkImageAdapterGd2.php:64 Stack trace 
Php :: set_magic_quotes_runtime php 7 
Php :: pdo error message 
Php :: laravel date diff 
Php :: validate either one field is required in laravel 
Php :: php json_encode float 
Php :: return json in php 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =