php - Simple_html_dom taking title and intro and display them on my page -
as want understand simple html dom bit playing around it, test options on localhost.
basically want take titles , intro's of website , display them on page.
the title <h2>
, intro <p>
.
what doing wrong?
<?php include 'simple_html_dom.php'; // create dom url $html = file_get_html('http://www.nu.nl/algemeen'); foreach($html->find('div[class=list-overlay]') $article){ $title['intro'] = $article->find('span[class=title]', 0)->innertext; $intro['details'] = $article->find('span[class=excerpt]', 0)->innertext; echo '<h2>'. $articles . '</h2> <p>'. $title .'</p>'; } ?>
edit: there double line in there.
your soulution somehow right. have few typos in variable names. here editation of code. have added few comments help understand.
<?php include 'simple_html_dom.php'; // create dom url $html = file_get_html('http://www.nu.nl/algemeen'); // exctract elements matching selector div[class=...] foreach($html->find('div[class=list-overlay]') $article){ // , each extract first (0) element matches span[class=title] $title = $article->find('span[class=title]', 0)->innertext; // , same intro, extract first element belongs selector $intro = $article->find('span[class=excerpt]', 0)->innertext; // , write downwards echo '<h2>'. $title . '</h2>'; echo '<p>' . $intro . '</p>'; } ?>
this solution isn't though. have bad construction of html not easy select articles, because don't have them in div id articles (for example. lucky man anyway, because provide xml feed of articles much easier parse (also less info transfer , on). can find here , extract titles , intros website.
php html simple-html-dom
No comments:
Post a Comment