Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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");
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #parsing #HTML #php
ADD COMMENT
Topic
Name
6+9 =