Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from url link to our website

Tags:

php

schedule

I have a problem with my website. I want to get all the schedule flight data from another website. I see its source code and get the url link for processing data. Can somebody tell me how to get the data from the current url link, then display it to our website with PHP?

like image 652
Agoeng Liu Avatar asked Sep 28 '13 05:09

Agoeng Liu


2 Answers

You can do it using file_get_contents() function. this function return html of provided url. then use HTML Parser to get required data.

$html = file_get_contents("http://website.com");

$dom = new DOMDocument();
$dom->loadHTML($html);
$nodes = $dom->getElementsByTagName('h3');
foreach ($nodes as $node) {
    echo $node->nodeValue."<br>"; // return <h3> tag data
} 


Another way to extract data using preg_match_all()

$html = file_get_contents($_REQUEST['url']);

preg_match_all('/<div class="swrapper">(.*?)<\/div>/s', $html, $matches);
   // specify the class to get the data of that class
foreach ($matches[1] as $node) {
    echo $node."<br><br><br>";
}
like image 166
Sumit Bijvani Avatar answered Nov 14 '22 06:11

Sumit Bijvani


Use file_get_contents

Sample code

<?php
$homepage = file_get_contents('http://www.google.com/');
echo $homepage;
?>
like image 38
Manish Goyal Avatar answered Nov 14 '22 05:11

Manish Goyal