Yii 1.1: simplehtmldom

A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
14 followers

OVERVIEW

  • A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
  • Supports invalid HTML.
  • Find tags on an HTML page with selectors just like jQuery.
  • Extract contents from HTML in a single line.

USAGE

Yii::import('ext.SimpleHTMLDOM.SimpleHTMLDOM');
// Create DOM from URL or file
$simpleHTML = new SimpleHTMLDOM;
$html = $simpleHTML->file_get_html('http://www.google.com/');
 
// Find all images
foreach($html->find('img') as $element)
       echo $element->src . '<br>';
 
// Find all links
foreach($html->find('a') as $element)
       echo $element->href . '<br>';

RESOURCE

http://simplehtmldom.sourceforge.net/

Total 2 comments

#16995 report it
Tanguy at 2014/04/21 03:16pm
More recent variant of this extension...

https://github.com/tpruvot/simple_html_dom

#12493 report it
nirmalroka at 2013/03/23 03:57pm
Great thank simple worked

Thanx simply worked. My Code Load MLB game schedule from espn, I worked hard but finally i got it, it returns array of game day, games vs concatinated with game time in array

public static function Load_MLB($name){
        Yii::import("application.vendors.*");
        include 'simple_html_dom.php';
        $html = file_get_html('http://espn.go.com/'.$name.'/schedule');
        $item = array();
        $games = array();
        $i =1;
        foreach($html->find('table.tablehead tbody') as $data) {
            $item['gameday'][$i]     = $data->find('tr.stathead td',0)->innertext;
            foreach($data->find('tr td') as $tdata):
            $games[$i][]= $tdata->innertext;
            endforeach;
            $i++;
 
        }
        $item = array_filter($item['gameday']);
        $j=1;
        $newkey = array();
        foreach($games as $game):
        if($game[1]=='RESULT'){
        } else {
            //$newkey = array();
            $newkey[$j]['gameday'] = $game[0];
            $game = array_filter($game);
            for($i=6;$i<sizeof($game);$i=$i+5):
            $newkey[$j][] = $game[$i].'--'.$game[$i+1];
            endfor;
 
        }
        $j++;
        endforeach;
 
 
        return $newkey;
 
    }

Leave a comment

Please to leave your comment.

Create extension