Web Fetching Woes.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icelord
Forum Newbie
Posts: 8
Joined: Sun May 19, 2002 9:19 pm

Web Fetching Woes.....

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply