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
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
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.
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); } ?> PHP: And use: include 'path/to/file/table.html'; PHP: 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??
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'); ?> PHP:
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..)
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; ?> PHP:
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 Code (markup): 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'); PHP: 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...
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..
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.
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 %>
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.
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))