Answer the question
In order to leave comments, you need to log in
How to parse a page with PHP Simple HTML DOM Parser?
Just started learning and can't figure it out.
There is a page from which you need to get the following:
From the post-contenedor diva Post
name - qsdfgh Inserted
image - iiimgur.com/HRrtdzw.gif
Tags - gol - hgg - ghf - hjj
Votes (Puntos) - 10
Favorites (FAVORITOS) - 1
Date post creation - 06/24/2013
ps Page taken from Google by request qsdfgh
Answer the question
In order to leave comments, you need to log in
Try phpQuery
<?php
include 'phpQuery.php';
$html = file_get_contents('http://demo.phpost.net/posts/arte/57/qsdfgh.html');
phpQuery::newDocumentHTML($html, $charset = 'utf-8');
$result = array();
$result['title'] = pq('div.post-title')->find('h1')->text();
$result['img'] = array();
foreach (pq('div.post-contenido')->find('img') as $img) {
$result['img'][] = pq($img)->attr('src');
}
$result['tags'] = array();
foreach (pq('div.tags-block')->find('a[rel=tag]') as $a) {
$result['tags'][] = pq($a)->text();
}
print_r($result);
Array
(
[title] => qsdfgh
[img] => Array
(
[0] => http://i.i.imgur.com/HRrtdzw.gif
)
[tags] => Array
(
[0] => gol
[1] => hgg
[2] => ghf
[3] => hjj
)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question