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 :: get first element of array php 
Php :: new line php 
Php :: carbon finer 
Php :: PHP Deprecated: Function create_function() 
Php :: Carbon Add Months To Date In Laravel 
Php :: php append line to file 
Php :: pass php variable in onclick function 
Php :: laravel migration add date of birth column 
Php :: wordpress get link to post by id 
Php :: run python script from batch file with arguments 
Php :: php elseif 
Php :: php check if associative array is null 
Php :: php parse url get path 
Php :: php artisan route:list for specific name 
Php :: wordpress global variable not working 
Php :: php validate date format 
Php :: laravel array remove key 
Php :: laravel orderby with relation 
Php :: laravel difference between current time and created time 
Php :: where laravel function 
Php :: woocommerce get post terms product 
Php :: faker 
Php :: try catch in laravel 
Php :: how to compare two versions in php 
Php :: slug in php 
Php :: laravel Filesystem chmod(): Operation not permitted 
Php :: laravel make directory 
Php :: php ziparchive compress folder 
Php :: php unset array key 
Php :: random number laravel faker 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =