Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error when using "File" and "FOpen"

    Hello,

    I have made a simple script that will go to a web site scrape the lottto results off and then create a web page with them on.

    I have permision from the owners of the site so i know they havn't blocked my ip address.

    But every time i run the script i get this error

    Warning: file(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/jueaprnv/public_html/numbers/index.php on line 8

    Warning: file(http://www.winonnumbers.com/T2_3.php?YEAR=2006): failed to open stream: Connection timed out in

    this is the script

    PHP Code:
    <?
        $year 
    $_GET["year"];
        if(!
    $year)
        {
            
    $year date("Y");
        }
        
        
    $lines file("http://www.winonnumbers.com/T2_3.php?YEAR=".$year);
        
    $filename "results-".$year.".htm";
        
    //$filename = "results.htm";
        
        
    if (file_exists($filename)) 
        {
            
    $outputfile fopen ($filename"w");
        } 
        else 
        {    
            
    $outputfile fopen ($filename"a");
            
    chmod($filename0777);
        }
            
        
    $drawdate '<td width="225" class="purpleTextBold">';
        
    $draw '<td width="70" class="purpleTextBold">';
        
    $number '<td width="32" align="center" class="purpleTextBold">';
        
    $bonus '<td width="60" align="center" class="purpleTextBold">';
        
        
    $topline 0;

        
    $outputstring "";
        foreach (
    $lines as $line_num => $line)
        {           
            if(
    strstr($line,"<html>"))
            {
                
    $outputstring .="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
                
    $outputstring .="<html>";
                
    $outputstring .="<head>";
                
    $outputstring .="<title>Irish Lottery Results</title>";
                
    $outputstring .="<style media=\"all\" type=\"text/css\">\n td { font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; }\n.hd {background-color:#000055; color:#ffffff; padding:4px 0 3px 0; font-weight:bold;}\n.cn {background-color:#F0F4FF; color:#000000; padding:4px 2px 3px 6px;}\n.dn {background-color:#E0E4EE; color:#000000; padding:4px 2px 3px 6px;}\n</style>";
                
    $outputstring .="</head>\n<body>";
            }
            if(
    strstr($line,$drawdate)) 
            {
                
    $drawnum 0;
                
    $topline 1;
                
    $stringpos strpos($line,$drawdate) + strlen($drawdate);        
                if(
    $stringpos != strlen($drawdate)) //draw date
                
    {        
                    
    $printline substr($line$stringpos);
                    
    $printline substr($printline,strlen($printline) - 7);
                    
                    
    $outputstring .= "<table width=\"380\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
                    
    $outputstring .= "<tr class=\"hd\">\n";
                    
    $outputstring .= "<td width=\"70\" nowrap>Draw Date</td>\n";
                    
    $outputstring .= "<td width=\"5\">&nbsp;</td>\n";
                    
    $outputstring .= "<td width=\"225\" colspan=\"12\" nowrap align=\"center\">"$printline ."</td>\n";
                    
    $outputstring .= "<td width=\"60\" align=\"center\">Bonus</td>\n";
                    
    $outputstring .= "</tr>\n";
                }            
            }
            if(
    strstr($line,$draw)) 
            {
                
    $ball 0;
                
    $stringpos strpos($line,$draw) + strlen($draw);        
                if(
    $stringpos != strlen($draw)) //draw date
                
    {        
                    
    $printline substr($line$stringpos);
                    
    $printline substr($printline,strlen($printline) - 7);
                    
    $outputstring .= "<tr";
                    if(
    $drawnum == || $drawnum == 2)
                    {
                    
    $outputstring .= " class=\"dn\"";
                    }
                    else
                    {
                    
    $outputstring .= " class=\"cn\"";
                    }
                    
    $outputstring .= ">\n<td width=\"70\">" .$printline."</td>";
                    
    $outputstring .= "<td width=\"5\">&nbsp;</td>";
                }
                
    $drawnum++;
                
    $topline 0;
                
            }
            if(
    strstr($line,$number)) 
            {
                
                
    $stringpos strpos($line,$number) + strlen($number);        
                if(
    $stringpos != strlen($number)) //draw date
                
    {        
                    
    $printline substr($line$stringpos);
                    
    $printline substr($printline,strlen($printline) - 7);
                    
    $outputstring .= "<td width=\"32\" align=\"center\">"$printline ."</td><td width=\"5\">&nbsp;</td>";
                 
    $ball++;
                 
    $topline 0;
                }
            
            }
            if(
    strstr($line,$bonus) && $topline == 0
            {
                
                
    $stringpos strpos($line,$bonus) + strlen($bonus);        
                if(
    $stringpos != strlen($bonus)) //draw date
                
    {        
                    
    $printline substr($line$stringpos);
                    
    $printline substr($printline,strlen($printline) - 7);
                    
    $outputstring .= "<td width=\"60\" align=\"center\">"$printline."</td>";
                    
    $ball ++;         
                }
            
            }
            
            if(
    $drawnum == && $ball == 7)
            {
            
    $outputstring .= "</tr>\n</table>\n<br>\n";
             
    $drawnum  0;
             
    $ball 0;
            }    
            if(
    $ball == 7)
            {
             
    $outputstring .= "</tr>\n";
             
    $ball 0;
            }
            if(
    strstr($line,"</html>"))
            {
                 
    $outputstring .= "</body>\n</html>";
            }
        }    
        if(
    $outputstring != "")
        {    
            
    fputs($outputfile,$outputstring);        
        }
            
        
    fclose($outputfile);
    ?>
    Now i would jsut think it my code. But it has worked for about 6 months and then suddenly stopped yesterday. I have sent an email to the host of my site to see iff they have change any settings.

    Any ideas what it could be or a different way of doing it.

    www.betfredcontent.com/numbers/index.php

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    I'm not sure exactly what is causing that error, but why not use file_get_contents instead, to do the same thing as this:

    PHP Code:
    $lines file("http://www.winonnumbers.com/T2_3.php?YEAR=".$year); 


    and using file_get_contents():

    PHP Code:
    $content file_get_contents("http://www.winonnumbers.com/T2_3.php?YEAR=".$year);
    $lines explode("\r\n",$content); 
    You may need to experiment with the string separator -- depending on the server, a line break could either be \n, \r, or \r\n....

    And if you need the line break at the end of each line, you could do a preg_split instead (I think this will work):

    PHP Code:
    $content file_get_contents("http://www.winonnumbers.com/T2_3.php?YEAR=".$year);
     
    $lines preg_split("/\r\n/",$content,-1,PREG_SPLIT_DELIM_CAPTURE); 
    otherwise you can simply do something like this:

    PHP Code:
    $content file_get_contents("http://www.winonnumbers.com/T2_3.php?YEAR=".$year);
     
    $lines explode("\r\n",$content);
    foreach (
    $lines as $key=>$val)
    {
        
    $lines[$key] = $val ."\r\n";

    good luck!







    Last edited by chump2877; 09-01-2006 at 03:27 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •