Xbox Mod Chips - Debt Help - Western Union - Gas Suppliers - Loan

PDA

View Full Version : php / xml? help


red_fiesta
Apr 23rd 2007, 3:05 pm
There is this page

http://www.svenskfotboll.se/uppland/table.aspx?TournamentId=44851

that i want to use here

http://www2.hemsida.net/sodraupsala/dan/tabel.php

at the moment its an iframe but i want it to work i some way where i pull data from that site?

Its an external site which i dont have control over, is there anyway of pulling there data so that when they update thier site it could on mine?

Thanks

Jim_
Apr 23rd 2007, 3:14 pm
Wouldn't that be content theft? :(

nico_swd
Apr 23rd 2007, 3:16 pm
It's possible, but you'll need their permission.

red_fiesta
Apr 23rd 2007, 3:23 pm
It's possible, but you'll need their permission.

Ok so if i got thier permission.. how would it be done..

I will use the answers here to suggest to them..



We are one of the teams shown in that league so i dont think it will be an issue i want to suggest to them how i would do it

tnks

nico_swd
Apr 23rd 2007, 3:27 pm
A cron job would call your script every X amount of time and copy their whole table in a database, or text file. The only thing you need is preg_match(), a good regular expression, and either allow_url_fopen or cURL enabled on your host.

nico_swd
Apr 23rd 2007, 3:44 pm
Actually, I figured you'd do it anyway, so whatever.

Run this script every X time you want:

<?php

// URL where to grab the table from
$url = 'http://www.svenskfotboll.se/uppland/table.aspx?TournamentId=44851';

// File name to save the results
$file = 'table.html';


if (ini_get('allow_url_fopen'))
{
$fp = @fopen($url, 'rb') OR die('Unable to open the URL.');
$data = '';

while (!feof($fp))
{
$data .= fgets($fp, 4096);
}
fclose($fp);
}
else if (function_exists('curl_init') AND $ch = @curl_init($url))
{
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
}
else
{
die('Unable to receive data from ' . $url);
}

if (preg_match('/<table\s+class="clTblStandings"\s+[^>]+>(.*?)<\/table>/si', $data, $table))
{
$fp = @fopen($file, 'w');
fwrite($fp, $table[0]);
fclose($fp);
}

?>



And use:


include 'path/to/file/table.html';


Wherever you want to display it.

red_fiesta
Apr 23rd 2007, 5:22 pm
Actually, I figured you'd do it anyway, so whatever.

Run this script every X time you want:

<?php

// URL where to grab the table from
$url = 'http://www.svenskfotboll.se/uppland/table.aspx?TournamentId=44851';

// File name to save the results
$file = 'table.html';


if (ini_get('allow_url_fopen'))
{
$fp = @fopen($url, 'rb') OR die('Unable to open the URL.');
$data = '';

while (!feof($fp))
{
$data .= fgets($fp, 4096);
}
fclose($fp);
}
else if (function_exists('curl_init') AND $ch = @curl_init($url))
{
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
}
else
{
die('Unable to receive data from ' . $url);
}

if (preg_match('/<table\s+class="clTblStandings"\s+[^>]+>(.*?)<\/table>/si', $data, $table))
{
$fp = @fopen($file, 'w');
fwrite($fp, $table[0]);
fclose($fp);
}

?>



And use:


include 'path/to/file/table.html';


Wherever you want to display it.



Two things..

I am just testing this to see if it works..

when i run the code i get

Unable to open the URL. returned to the screen any ideas why?

also is there no way to make sure this code is run when the page is loaded rather than setting up so way to run it at certain times??

nico_swd
Apr 23rd 2007, 5:31 pm
Seems like your host doesn't support that. Before worrying about when you run the script, you should worry about being able to run it at all.

Does this work for you?

<?php

echo file_get_contents('http://www.svenskfotboll.se/uppland/table.aspx?TournamentId=44851');

?>

red_fiesta
Apr 23rd 2007, 5:43 pm
PHP Fatal error: Call to undefined function: file_get_contents() in C:\inetpub\wwwroot\test\admin\cron\test2.php on line 3

(It works locally. just not remotely..)

red_fiesta
Apr 23rd 2007, 5:51 pm
what can i do to fix this?

nico_swd
Apr 23rd 2007, 5:52 pm
Okay, so your server is running an old version of PHP. Does this work?

<?php

$url = 'http://www.svenskfotboll.se/uppland/table.aspx?TournamentId=44851';

$fp = fopen($url, 'rb') OR die('Unable to open the URL.');
$data = '';

while (!feof($fp))
{
$data .= fgets($fp, 4096);
}
fclose($fp);

echo $data;

?>

red_fiesta
Apr 23rd 2007, 5:56 pm
Works locally but remotely get

Unable to open the URL.

nico_swd
Apr 23rd 2007, 6:03 pm
That's gonna be a problem. Your host doesn't allow connections to other hosts. And cURL isn't installed either... so I don't know what to do at this point.

You can try this, but I doubt it's gonna work:

Place this in a .htaccess file in your root dir.

php_value allow_url_fopen 1


Or try placing this at the top of your script. (It's probably not gonna work either, but it's worth a try)

ini_set('allow_url_fopen', '1');


That's all I can think of...


EDIT:

Talk to your host and ask if they can enable this. And tell them to upgrade PHP... They're running a version below 4.0.3... while 5.2.1 is out...

red_fiesta
Apr 23rd 2007, 6:08 pm
nope neither worked.. this server does allow for asp as well. can i do it in that?? or can i install what i need? thanks for the help so far..

nico_swd
Apr 23rd 2007, 6:16 pm
I don't know anything about ASP, but I don't think it'll work either.

What you need is allow_url_fopen to be enabled in your php.ini file, but you won't be able to do that yourself. Email your host and ask if they can do it. Or ask if they can install cURL (http://curl.haxx.se/).

red_fiesta
Apr 24th 2007, 4:58 am
A way of grabbing code in asp is

<%
url = "http://www.svenskfotboll.se/uppland/table.aspx?TournamentId=44851"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
Response.write xmlhttp.responseText
set xmlhttp = nothing
%>

nico_swd
Apr 24th 2007, 5:04 am
And does this work for you?

red_fiesta
Apr 24th 2007, 5:48 am
yeah.. i know need to work out how to read just the table

nico_swd
Apr 24th 2007, 5:53 am
I can't help you with that since I don't know anything about ASP. But if I was you, I'd email your host and ask if they could enable that for PHP as well... there's no point in having it enabled in ASP but not PHP.

red_fiesta
Apr 24th 2007, 5:55 am
Yeah i have

Iguess for the asp i need to do something similar to this..


if (preg_match('/<table\s+class="clTblStandings"\s+[^>]+>(.*?)<\/table>/si', $data, $table))