php / xml? help

Discussion in 'PHP' started by red_fiesta, Apr 23, 2007.

  1. #1
    red_fiesta, Apr 23, 2007 IP
  2. Jim_

    Jim_ Peon

    Messages:
    72
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Wouldn't that be content theft? :(
     
    Jim_, Apr 23, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    It's possible, but you'll need their permission.
     
    nico_swd, Apr 23, 2007 IP
  4. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    red_fiesta, Apr 23, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    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 23, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    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.
     
    nico_swd, Apr 23, 2007 IP
  7. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7


    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??
     
    red_fiesta, Apr 23, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    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:
     
    nico_swd, Apr 23, 2007 IP
  9. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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 23, 2007 IP
  10. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    what can i do to fix this?
     
    red_fiesta, Apr 23, 2007 IP
  11. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #11
    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:
     
    nico_swd, Apr 23, 2007 IP
  12. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Works locally but remotely get

    Unable to open the URL.
     
    red_fiesta, Apr 23, 2007 IP
  13. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #13
    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...
     
    nico_swd, Apr 23, 2007 IP
  14. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    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..
     
    red_fiesta, Apr 23, 2007 IP
  15. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #15
    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.
     
    nico_swd, Apr 23, 2007 IP
  16. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    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
    %>
     
    red_fiesta, Apr 24, 2007 IP
  17. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #17
    And does this work for you?
     
    nico_swd, Apr 24, 2007 IP
  18. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    yeah.. i know need to work out how to read just the table
     
    red_fiesta, Apr 24, 2007 IP
  19. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #19
    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.
     
    nico_swd, Apr 24, 2007 IP
  20. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    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))
     
    red_fiesta, Apr 24, 2007 IP