Page 1 of 1

Web Fetching Woes.....

Posted: Sat Mar 08, 2003 7:46 pm
by icelord
This script that I wrote seems to be really buggy....
It is supposed to fetch latest lottery numbers from lottery.ca
I have also made it so that it takes the balls that I drew instead of lottery balls that they have.
It keeps giving me -462 as my output :? , but it should really give me 6 images as output.
I ran out of ideas on what it could be. :cry:
I have tried just the $StartPos, $EndPos and $String part without all of the replacing and stuff, and it still gives me -462. I think that the problem is somewhere withing the $String function.
(But then again I am a newbie..... what do I know) :wink:

Code: Select all

$Lotto = array(
"../temp/lotto.cache",
"http://www.lottery.ca/nontariolot/n649/index.shtml",
"Bonus</small></font></td>",
"<td width="308" colspan="7"><hr color="#F8DB36" noshade>"
);

function StoreData ($file, $url, $start, $end) &#123;
     $time = split(" ", microtime());
     $cache_time = filectime($file) + 10800;
     if ($cache_time < $time&#1111;1]) &#123;
              $fp = fopen($url,"r");
              $ReadIn = fread($fp,100000); 
              $StartPos = strpos($ReadIn, $start);
              $EndPos = strpos($ReadIn, $end);
              $String = $EndPos - $StartPos;
              $code = ereg_replace("http://www.lottery.ca/art/smballs/","images/blue/",$String);
              $code = ereg_replace("http://www.lottery.ca/art/redsmballs/","images/red/",$String);
              $fcache = fopen($file, "w");
              fputs($fcache, $code);
              fclose($fcache);
              $final=$code;  	
     &#125; else &#123;
               $final=$ReadIn;
     &#125;
return $final;
&#125;

$lottoStore = StoreData($file=$Lotto&#1111;0], $url=$Lotto&#1111;1], $start=$Lotto&#1111;2], $end=$Lotto&#1111;3]);

echo $lottoStore;
Any help would be greatly appreciated.

IcE.

Posted: Sun Mar 09, 2003 5:13 am
by volka
int strpos ( string haystack, string needle [, int offset])
$StartPos = strpos($ReadIn, $start);
$EndPos = strpos($ReadIn, $end);
$String = $EndPos - $StartPos;
$StartPos and $EndPos are numbers.
So you're probably intersted in http://www.php.net/manual/de/function.substr.php