Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('simple_html_dom.php');
- $page = $_GET['page'];
- $html = file_get_html('http://www.hdvietnam.com/diendan/content.php?page='.$page);
- $count_tin = 0;
- echo "{".'"MangTin":'."[";
- $posts = $html->find(".fullwidth");
- foreach($posts as $post){
- $titleLeft = $post->find(".leftcol .title .article_preview a span",0)->innertext;
- $linkLeft = $post->find(".leftcol .title .article_preview a",0)->href;
- $contentLeft = $post->find(".leftcol div[class=cms_article_txt_content postcontainer]",0)->innertext;
- $imgLeft = cleanImg($imgLeft, $post, ".leftcol .cms_article_preview_image");
- $titleRight = $post->find(".rightcol .title .article_preview a span",0)->innertext;
- $linkRight = $post->find(".rightcol .title .article_preview a",0)->href;
- $contentRight = $post->find(".rightcol div[class=cms_article_txt_content postcontainer]",0)->innertext;
- $imgRight = cleanImg($imgRight, $post, ".rightcol .cms_article_preview_image");
- $titleLeft = strip_tags($titleLeft);
- $titleRight = strip_tags($titleRight);
- $titleLeft = str_replace(" ","",$titleLeft);
- $titleRight = str_replace(" ","",$titleRight);
- if(strlen($titleLeft)>0){
- echo(createObjectJSON("Title",$titleLeft).'"'.',"Link":'.'"'.$linkLeft.'"'.',"Image":'.'"'.$imgLeft.'"'.',"Content":'.'"'.$contentLeft.'"'.'},');
- }
- if(strlen($titleRight)>0){
- if($count_tin==9){
- $count_tin++;
- echo(createObjectJSON("Title",$titleRight).'"'.',"Link":'.'"'.$linkRight.'"'.',"Image":'.'"'.$imgRight.'"'.',"Content":'.'"'.$contentRight.'"'.'}');
- }
- else if($count_tin<10){
- $count_tin++;
- echo(createObjectJSON("Title",$titleRight).'"'.',"Link":'.'"'.$linkRight.'"'.',"Image":'.'"'.$imgRight.'"'.',"Content":'.'"'.$contentRight.'"'.'},');
- }
- }
- }
- echo "]}";
- function createObjectJSON($nameJO, $JO){
- return '{"'.$nameJO.'":'.'"'.$JO;
- }
- function cleanImg($img, $post, $class){
- $img = $post->find($class,0)->style;
- $img = str_replace("')","",$img);
- $img = str_replace("background-image: url('","",$img);
- return $img;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement