Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  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. $count_tin = 0;
  6.  
  7. echo "{".'"MangTin":'."[";
  8. $posts = $html->find(".fullwidth");
  9. foreach($posts as $post){
  10. $titleLeft = $post->find(".leftcol .title .article_preview a span",0)->innertext;
  11. $linkLeft = $post->find(".leftcol .title .article_preview a",0)->href;
  12. $contentLeft = $post->find(".leftcol div[class=cms_article_txt_content postcontainer]",0)->innertext;
  13. $imgLeft = cleanImg($imgLeft, $post, ".leftcol .cms_article_preview_image");
  14.  
  15. $titleRight = $post->find(".rightcol .title .article_preview a span",0)->innertext;
  16. $linkRight = $post->find(".rightcol .title .article_preview a",0)->href;
  17. $contentRight = $post->find(".rightcol div[class=cms_article_txt_content postcontainer]",0)->innertext;
  18. $imgRight = cleanImg($imgRight, $post, ".rightcol .cms_article_preview_image");
  19.  
  20. $titleLeft = strip_tags($titleLeft);
  21. $titleRight = strip_tags($titleRight);
  22.  
  23. $titleLeft = str_replace("&nbsp;","",$titleLeft);
  24. $titleRight = str_replace("&nbsp;","",$titleRight);
  25.  
  26. if(strlen($titleLeft)>0){
  27. echo(createObjectJSON("Title",$titleLeft).'"'.',"Link":'.'"'.$linkLeft.'"'.',"Image":'.'"'.$imgLeft.'"'.',"Content":'.'"'.$contentLeft.'"'.'},');
  28. }
  29. if(strlen($titleRight)>0){
  30. if($count_tin==9){
  31. $count_tin++;
  32. echo(createObjectJSON("Title",$titleRight).'"'.',"Link":'.'"'.$linkRight.'"'.',"Image":'.'"'.$imgRight.'"'.',"Content":'.'"'.$contentRight.'"'.'}');
  33. }
  34. else if($count_tin<10){
  35. $count_tin++;
  36. echo(createObjectJSON("Title",$titleRight).'"'.',"Link":'.'"'.$linkRight.'"'.',"Image":'.'"'.$imgRight.'"'.',"Content":'.'"'.$contentRight.'"'.'},');
  37. }
  38. }
  39. }
  40. echo "]}";
  41.  
  42. function createObjectJSON($nameJO, $JO){
  43. return '{"'.$nameJO.'":'.'"'.$JO;
  44. }
  45. function cleanImg($img, $post, $class){
  46. $img = $post->find($class,0)->style;
  47. $img = str_replace("')","",$img);
  48. $img = str_replace("background-image: url('","",$img);
  49. return $img;
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement