KasparsK Posted July 12, 2012 Report Share Posted July 12, 2012 (edited) Sveiki .txt faila saturs (piemēram) 2005-2006 Miami Pos. Sec Pos Name PF C C. Bosh PF C U. Haslem SF SG L. James SG PG D. Wade PG PG M. Chalmers SF SG S. Battier SG SF M. Miller PG PG N. Cole SF SG J. Jones PF C J. Howard C C J. Anthony C PF E. Curry C C D. Pittman Kā var izvilkt no katras rindas 'Pos.', 'Sec Pos', 'name' kolonām atsevišķi... Piemēram $var[1] = 'PF'; $var[2] = 'C'; $var[3] = 'C. Bosh'; un tad atkal jaunu rindu izvelkam atsevisķi piemēram: $var[1] = 'PF'; $var[2] = 'C'; $var[3] = 'U. Haslem'; Mans netikt galā, pagoogloju, tik un tā nesanāca. P.S par faila satura iegūšanu variet nerakstīt tas man jau ir... Paldies, Kaspars. Edited July 12, 2012 by KasparsK Quote Link to comment Share on other sites More sharing options...
briedis Posted July 12, 2012 Report Share Posted July 12, 2012 Ielasi failu ar file() funkciju (kas jau sadala masīvā pa rindiņai) un tad ejo cauri pa rindiņai un izmantojot preg_split() sadali masīvā katru rindiņu. preg_splitam var izmantot regulāro izteiksi, kas matcho vairākas atstarpes. Quote Link to comment Share on other sites More sharing options...
anonīms Posted July 13, 2012 Report Share Posted July 13, 2012 Varu nopārdot NBA statistikas kodu )) © GM Quote Link to comment Share on other sites More sharing options...
y2ok Posted July 13, 2012 Report Share Posted July 13, 2012 (edited) Lūk, kā piemēru vari ņemt šo. Izlasīs tikai rindas, kurās ir vismaz seši space <?php $rows = file('text.txt'); foreach ($rows as $row) { if (strpos($row, " ")) { echo $row.'<br />'; } } ?> Tālāk, ja tev nevajag pirmo rindu (Pos ; Sec.pos ; Name), tad vari vienkārši ar ifu nočekot, ja ir pirmā rinda, tad neizvada. Tālāk, vienkārši ar implode visu sabāz arrayā. Edited July 13, 2012 by y2ok Quote Link to comment Share on other sites More sharing options...
Mr.Key Posted July 13, 2012 Report Share Posted July 13, 2012 (edited) http://lv.php.net/ma...ion.fgetcsv.php http://lv.php.net/manual/en/function.str-getcsv.php Edited July 13, 2012 by Mr.Key Quote Link to comment Share on other sites More sharing options...
anonīms Posted July 13, 2012 Report Share Posted July 13, 2012 ā, atkodu, kas ir KasparsK. Čalīt esi vēl parādā pie 100Ls. Quote Link to comment Share on other sites More sharing options...
aaxc Posted July 17, 2012 Report Share Posted July 17, 2012 (edited) Varu piedāvāt šādu risinājumu, # class gatherData ($filename) class gatherData { # set used variables private $file_data; # Preload file public function __construct ($filename) { self::setFileData($filename); } # Load data into array public function getData() { $return = array(); foreach (self::getFileData() as $key => $value) { # Ignore 1st 3 lines of unnecessary code if ($key>2) { $large_array = explode(' ', $value); foreach ($large_array as $info) { if (trim($info)) { $return[$k-2][] .= $info; } } } } # return new array return $return; } # set '$file_data' variable private function setFileData ($file_data) { $file_data = file($file_data); $this -> file_data = $file_data; } # get '$file_data' variable private function getFileData() { return $this -> file_data; } } $aaxc = new gatherData('data.txt'); $new_array = $aaxc -> getData(); print_r($new_array); Takā preg_split nepārzinu labi, tad kāds cits var uztaisīt labāku variantu gan jau getData funkcijai. Edited July 17, 2012 by aaxc Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 17, 2012 Report Share Posted July 17, 2012 Kāpēc tu liec tās atstarpes (pirms un pēc «->», pirms «)» un pēc «(» utt.)? Tas nav ne PEAR, ne Zend... ne jebkurš cits _coding style_, kuru pārzinu. Quote Link to comment Share on other sites More sharing options...
aaxc Posted July 17, 2012 Report Share Posted July 17, 2012 lol, man personiigi vieglaak paarskatiit kodu taadaa veidaa. Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted July 17, 2012 Report Share Posted July 17, 2012 Kāpēc tu liec tās atstarpes (pirms un pēc «->», pirms «)» un pēc «(» utt.)? Tas nav ne PEAR, ne Zend... ne jebkurš cits _coding style_, kuru pārzinu. Kapeec tu izmanto markdown vietaas kur tas nav atbalstiits :) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 17, 2012 Report Share Posted July 17, 2012 Kāpēc nē? :D Ieradums. Quote Link to comment Share on other sites More sharing options...
Mr.Key Posted July 17, 2012 Report Share Posted July 17, 2012 lol, man personiigi vieglaak paarskatiit kodu taadaa veidaa. Pirmkārt, tas nav lol. Otrkārt, ja raksti kodu priekš sevis, tad nedalies ar viņu, bet ja dalies, tad raksti tā, lai citiem būtu ērtāk pārskatīt. Quote Link to comment Share on other sites More sharing options...
waplet Posted July 17, 2012 Report Share Posted July 17, 2012 Eu nu čali jums te baigais troļļojamais panesās par koda pieraksti :D Quote Link to comment Share on other sites More sharing options...
marrtins Posted July 17, 2012 Report Share Posted July 17, 2012 Jāpakapā tak mati, sen nav kapāti :P Quote Link to comment Share on other sites More sharing options...
aaxc Posted July 17, 2012 Report Share Posted July 17, 2012 (edited) Turpinot spamu ... @MrKey, kur problēma? Vai kods kā tāds neapmierina? Es tikai gribēju palīdzēt... Edited July 17, 2012 by aaxc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.