View difference between Paste ID: ji4mPBZh and i8CnN75D
SHOW: | | - or go back to the newest paste.
1
<?php
2-
    include('simple_html_dom.php');
2+
include('simple_html_dom.php');
3-
    $page = $_GET['page'];
3+
$page     = $_GET['page'];
4-
	$html = file_get_html('http://www.hdvietnam.com/diendan/content.php?page='.$page);
4+
$html     = file_get_html('http://www.hdvietnam.com/diendan/content.php?page=' . $page);
5-
	$count_tin = 0;
5+
$response = array();
6-
	
6+
$posts    = $html->find("div.fullwidth");
7-
	echo "{".'"MangTin":'."[";
7+
foreach($posts as $post) {
8-
	$posts = $html->find(".fullwidth");
8+
	if($post->find(".leftcol") != null) {
9-
	foreach($posts as $post){
9+
		$link       = $post->find(".leftcol .title .article_preview a", 0);
10-
	    $titleLeft = $post->find(".leftcol .title .article_preview a span",0)->innertext;
10+
		$title      = $link->find("span", 0);
11-
	    $linkLeft = $post->find(".leftcol .title .article_preview a",0)->href;
11+
		$content    = $post->find(".leftcol div[class=cms_article_txt_content postcontainer]", 0);
12-
	    $contentLeft = $post->find(".leftcol div[class=cms_article_txt_content postcontainer]",0)->innertext;
12+
		$img        = cleanImg($post, ".leftcol .cms_article_preview_image");
13-
	    $imgLeft = cleanImg($imgLeft, $post, ".leftcol .cms_article_preview_image");
13+
		$response[] = array(
14-
	    
14+
			'Title'   => str_replace("&nbsp;", "", strip_tags($title->innertext)),
15-
	    $titleRight = $post->find(".rightcol .title .article_preview a span",0)->innertext;
15+
			'Link'    => $link->href,
16-
	    $linkRight = $post->find(".rightcol .title .article_preview a",0)->href;
16+
			'Image'   => $img,
17-
	    $contentRight = $post->find(".rightcol div[class=cms_article_txt_content postcontainer]",0)->innertext;
17+
			'Content' => $content->innertext
18-
	    $imgRight = cleanImg($imgRight, $post, ".rightcol .cms_article_preview_image");
18+
		);
19-
	    
19+
20-
	    $titleLeft = strip_tags($titleLeft);
20+
	if($post->find(".rightcol") != null) {
21-
	    $titleRight = strip_tags($titleRight);
21+
		$link       = $post->find(".rightcol .title .article_preview a", 0);
22-
	    
22+
		$title      = $link->find("span", 0);
23-
	    $titleLeft = str_replace("&nbsp;","",$titleLeft);
23+
		$content    = $post->find(".rightcol div[class=cms_article_txt_content postcontainer]", 0);
24-
	    $titleRight = str_replace("&nbsp;","",$titleRight);
24+
		$img        = cleanImg($post, ".rightcol .cms_article_preview_image");
25-
	    
25+
		$response[] = array(
26-
	    if(strlen($titleLeft)>0){
26+
			'Title'   => str_replace("&nbsp;", "", strip_tags($title->innertext)),
27-
	        echo(createObjectJSON("Title",$titleLeft).'"'.',"Link":'.'"'.$linkLeft.'"'.',"Image":'.'"'.$imgLeft.'"'.',"Content":'.'"'.$contentLeft.'"'.'},');
27+
			'Link'    => $link->href,
28-
	    }
28+
			'Image'   => $img,
29-
	    if(strlen($titleRight)>0){
29+
			'Content' => $content->innertext
30-
	        if($count_tin==9){
30+
		);
31-
	        	$count_tin++;
31+
32-
	        	echo(createObjectJSON("Title",$titleRight).'"'.',"Link":'.'"'.$linkRight.'"'.',"Image":'.'"'.$imgRight.'"'.',"Content":'.'"'.$contentRight.'"'.'}');
32+
}
33-
	        }
33+
header('Content-Type: application/json');
34-
	        else if($count_tin<10){
34+
echo json_encode(array('MangTin' => $response));
35-
	        	$count_tin++;
35+
36-
	        	echo(createObjectJSON("Title",$titleRight).'"'.',"Link":'.'"'.$linkRight.'"'.',"Image":'.'"'.$imgRight.'"'.',"Content":'.'"'.$contentRight.'"'.'},');
36+
function cleanImg($post, $class) {
37-
	        }
37+
	$img = $post->find($class, 0)->style;
38-
	    }
38+
	$img = str_replace("')", "", $img);
39
	$img = str_replace("background-image: url('", "", $img);
40-
	echo "]}";
40+
	return $img;
41-
	
41+
}