Advertisement
TuoiTeen

Untitled

Sep 2nd, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. include('simple_html_dom.php');
  3. $page     = $_GET['page'];
  4. $html     = file_get_html('http://www.hdvietnam.com/diendan/content.php?page=' . $page);
  5. $response = array();
  6. $posts    = $html->find("div.fullwidth");
  7. foreach($posts as $post) {
  8.     if($post->find(".leftcol") != null) {
  9.         $link       = $post->find(".leftcol .title .article_preview a", 0);
  10.         $title      = $link->find("span", 0);
  11.         $content    = $post->find(".leftcol div[class=cms_article_txt_content postcontainer]", 0);
  12.         $img        = cleanImg($post, ".leftcol .cms_article_preview_image");
  13.         $response[] = array(
  14.             'Title'   => str_replace("&nbsp;", "", strip_tags($title->innertext)),
  15.             'Link'    => $link->href,
  16.             'Image'   => $img,
  17.             'Content' => $content->innertext
  18.         );
  19.     }
  20.     if($post->find(".rightcol") != null) {
  21.         $link       = $post->find(".rightcol .title .article_preview a", 0);
  22.         $title      = $link->find("span", 0);
  23.         $content    = $post->find(".rightcol div[class=cms_article_txt_content postcontainer]", 0);
  24.         $img        = cleanImg($post, ".rightcol .cms_article_preview_image");
  25.         $response[] = array(
  26.             'Title'   => str_replace("&nbsp;", "", strip_tags($title->innertext)),
  27.             'Link'    => $link->href,
  28.             'Image'   => $img,
  29.             'Content' => $content->innertext
  30.         );
  31.     }
  32. }
  33. header('Content-Type: application/json');
  34. echo json_encode(array('MangTin' => $response));
  35.  
  36. function cleanImg($post, $class) {
  37.     $img = $post->find($class, 0)->style;
  38.     $img = str_replace("')", "", $img);
  39.     $img = str_replace("background-image: url('", "", $img);
  40.     return $img;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement