Friday, December 17, 2010

Get data from other site in php

$html = file_get_contents("http://www.website.com/blog/");
now print_r the $html and you will find all the content on your page


To see a specific part
preg_match_all (  '/< li >.*?< h1 >< a href=" (. *? ) ">(. *? )< \/ a ><\/ h1 >.*?(. *?)<\/s pan>.*?(.*?)<\/di v>.*?<\/ li>/ s',
    $html,
    $posts, // will contain the blog posts
    PREG_SET_ORDER // formats data into an array of posts
);
for each $posts as $post)

{
    $link = $post[1];
    $title = $post[2];
    $date = $post[3];
 $content = $post[4];

    // do something with data
}

echo the variable in foreach loop




No comments:

Post a Comment