Re: File reading help with Syntax

From: Date: Fri, 19 Jul 2002 00:41:43 +0000
Subject: Re: File reading help with Syntax
Groups: php.general 
Request: Send a blank email to php-general+get-108395@lists.php.net to get a copy of this message
>I am getting data froma website for stock information. If I type in the >brower the URL I get a text file display list this; > >Date,Open,High,Low,Close,Volume >16-Jul-02,7.92,8.10,7.68,7.82,605500 >15-Jul-02,7.98,8.02,7.59,8.02,577200 >12-Jul-02,7.80,8.00,7.57,7.95,411100 >11-Jul-02,7.82,7.94,7.34,7.80,802400 > >Now I want to break each line and then seperate each line by the commas. The >amount of linesin the file is never known so I assume I have to use >something like a foreach or while statement,but I am not sure the best way >to do it. This is what I have so far. > > $Symbol = "IKN"; $LookupUrl = >"http://demos.inxdesign.com/download?sym=$Symbol&format=.txt"; >$Results = >implode('', file("$LookupUrl")); > $Data = array(); split("\n", $Results) = array_push($Data, $line) file() is already *GIVING* you an array of each line. You simple need to look at each one and separate by commas. $data = file($LookupUrl); while(list(,$line) = each($data)){ $values = explode(',', $line); var_dump($values); } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#108395) next »