Click to See Complete Forum and Search --> : Pulling info from other sites


damon2003
09-09-2003, 05:12 AM
Has anyone any experience of pulling info such as weather info and embedding it in your own web page using php. I know this can be done using PHP. are there any free services available for this. And what about 'web services'? is this a similar thing? thanks a lot

Khalid Ali
09-09-2003, 05:45 AM
web services may or may not be a similar thing,however since I am not a php expert, Icould be wrong on this,
I seriously doubt that php supports web services standards( you will need to learn Java for this)

damon2003
09-09-2003, 05:55 AM
thanks,
actually what I heard was that XML and SOAP can be used with PHP to make use of web services. However I am more interested in using conventional PHP to pull info from other sites such as weather info, I have heard php can be used to pull this info???

Khalid Ali
09-09-2003, 06:35 AM
you mean php can read a url ? if so ..I think you can do this using something like


<?php
$filename="http://www.foxnews.com/index.html";
$fp = @fopen($filename, 'rb');
$contents = fread ($fp, filesize ($filename));
echo $contents;
?>

pyro
09-09-2003, 07:14 AM
Yes, if you can get the weather in an XML feed, that would be excellent! You could then use PHP to parse the XML file and display it how you'd like. Or, as Khalid said, you can read external files with PHP as well, though you won't be able to read the filesize of external files, so you will probably want to do it more like this:

<?php
$filename="http://www.php.net";
$contents = @file($filename);
foreach ($contents as $line) {
echo $line;
}
?>

damon2003
09-09-2003, 07:20 AM
is it then possible to use regular expressions to just get a section of the html from the other page? how would this be done,
thanks a lot for your time!

pyro
09-09-2003, 07:47 AM
Yeah, you could use regexp to split out the part you need. I'd need to see the code to give more specific help, though (and you'd want there to be something unique that you can split it at)...

damon2003
09-09-2003, 10:46 AM
I dont actually have any code yet, I am still researching how to do this.
Say if I needed wanted to pull info from the first table of page how could this be done using regular expressions?
thanks a lot

pyro
09-09-2003, 11:36 AM
Something like this:

<?php
$filename="http://www.php.net";
$contents = @file($filename);
$lines = "";
foreach ($contents as $line) {
$lines .= $line;
}
$lines = preg_replace("/\\\\n/","",$lines);
preg_match("/<table(.*?)>(.*?)<\\/table>/",$lines, $matches);
echo $matches[0];
?>