Jump to content

Get data from a webpage.


lynxus

Recommended Posts

Hi guys.

 

how can i do this:

a script runs ( i want it to call another script but wont wait for it to complete , IE: it will call getdata.php but will carry on and end like it would, Leaving getdata.php to run by itself. )

 

i want to be able to get getdata.php to load http://www.ip-db.com/212.125.94.168 and then get the Location information and put them in vars.

 

so something like:

 

somescript.php
<?php

call getdata.php?ip=212.125.94.168;

echo "now doing the rest of this script and end without waiting for getdata.php

?>

getdata.php
<?php
$ip = $_GET['ip'];

get some vars from http://www.ip-db.com/$ip

$city = ( the city bit of the page );
$country = ( the country bit );

?>

 

 

Any ideas will great?

 

Thanks

Graham

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/169073-get-data-from-a-webpage/
Share on other sites

<?php

function getipdata($theip) {
  return file_get_contents("http://www.ip-db.com/$theip");
}

function get_it($content, $what) {
  if($what == "city") {
  //funky regex here to get city
  return $city;
  } elseif ($what == "country") {
  //funky regex here to get country
  return $city;
  }
}

$data = getipdata(212.125.94.168);
echo "CITY:".get_it($data, "city"); 
echo "COUNTRY:".get_it($data, "country"); 

 

 

this way it only gets the data once...

 

I mean I'm crap w/ regex so that's how I'd do it..

 

one could if they were good, setup one HUGE expression to get all the data... then set it as an array

I dont mind waiting, however i want to minimise the runtime of the main script ( if the external site is off ) it will cause the other script to wait .

 

but yeh i dont mind waiting.

 

If its a case of waiting then all the code can be in the one script insted of an external script.

 

eitherway I still have no clue how to get the data from the webpage itself and put it into vars for me to use.

 

Any ideas?

 

thanks

G

<?php

function getipdata($theip) {
  return file_get_contents("http://www.ip-db.com/$theip");
}

function get_it($content, $what) {
  if($what == "city") {
  //funky regex here to get city
  return $city;
  } elseif ($what == "country") {
  //funky regex here to get country
  return $city;
  }
}

$data = getipdata(212.125.94.168);
echo "CITY:".get_it($data, "city"); 
echo "COUNTRY:".get_it($data, "country"); 

 

 

this way it only gets the data once...

 

I mean I'm crap w/ regex so that's how I'd do it..

 

one could if they were good, setup one HUGE expression to get all the data... then set it as an array

 

yeah thats sorta what im looking for. However im also useless at regex( ive tried and failed oh so many times lol )

If anyone else has any input to the above that would be awesome!

 

in the source of that page id like it to look at :

<b>City:</b></font></td><td width="10"> </td><td><font face="arial" size="2">Cheltenham</td>

It then can see that City : = cheltenham?

 

 

 

thanks

G

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.