dot Posted March 15, 2005 Report Share Posted March 15, 2005 man ir aptuveni taads skripts: <?php $fails= file("dati.txt"); for($i=0;$i< count($fails);$i++){ $dati= explode("||", $fails[$i]); echo "$dati[0] $dati[1]"; } haytaajums ir taads kaa izdzeest sho konkreeto rindinju no txt faila? piemeeram nospiezzot uz linka. paldies jau iepriekss.. Link to comment Share on other sites More sharing options...
Kavacky Posted March 15, 2005 Report Share Posted March 15, 2005 (edited) $nr - rindas nummurs, kura jādzēš. Pirmās rindas nummurs ir 0. $data = file("dati.txt"); $data_part_1 = array_slice($data,0, $nr); $data_part_2 = array_slice($data, $nr + 1, count($data)); $data = array_merge($data_part_1, $data_part_2); $output = implode("", $data); $f = fopen("dati.txt", "w"); flock($f, LOCK_EX); fwrite($f, $output); flock($f, LOCK_UN); fclose($f); Edited March 15, 2005 by Kavacky Link to comment Share on other sites More sharing options...
bubu Posted March 15, 2005 Report Share Posted March 15, 2005 (edited) Nav labi. Tev izmantos daudz atmiņas, ja fails būs liels. Labāk veidot temporary failu: $rinda = 10; // ko dzēst $f = fopen('fails.txt', 'r'); // jāveido kāds bloķēšanas mehānisms, lai netiktu mainīts faila saturs šī koda izpildes laikā (piemēram ar cita faila palīdzību) $f2 = fopen('fails.new', 'w'); $i = 0; while ($i++<$rinda) { fputs($f2, fgets($f)); } fgets($f); // izlaižam dzēšamo rindu while (!feof($f)) { fputs($f2, fgets($f)); } fclose($f2); fclose($f); unlink('fails.txt'); rename('fails.new', 'fails.txt'); // tagad drīkstētu atbloķēt failu Edited March 15, 2005 by bubu Link to comment Share on other sites More sharing options...
kirils Posted March 15, 2005 Report Share Posted March 15, 2005 shkjiet, ka liidz pat muusu dienaam nav atrasts *efektiivs* veids kaa no php izdzeest vienu (paaris) rindinjas no faila. ar kaadu zemaaka liimenja valodu var meegjinaat failu sisteemu chakareet.. Link to comment Share on other sites More sharing options...
blackhalt Posted March 15, 2005 Report Share Posted March 15, 2005 (edited) Tajā dati.txt katras līnijas sakumā vajag kaut kādu unikalu identifikatoru, kas nav citur tālāk līnijā: dati.txt 1|||dati1||dati2||1 2|||dati1||dati2||2 3|||dati1||dati2|| 4|||dati1||dati22|| 5|||dati1||dati2||3 tipa tas unikālais buus tas kaukas||| tad: <php$vards='2|||';$fails=file('dati.txt');$taspats=fopen('dati.txt','w');foreach($fails as $line){if(!strstr($line,$vards)){fputs($taspats,$line);}}fclose($taspats);?>[code]izdzēsīs otro līniju Edited March 15, 2005 by blackhalt Link to comment Share on other sites More sharing options...
kirils Posted March 15, 2005 Report Share Posted March 15, 2005 Tajā dati.txt katras līnijas sakumā vajag kaut kādu unikalu identifikatoru, kas nav citur tālāk līnijā:dati.txt 1|||dati1||dati2||1 2|||dati1||dati2||2 3|||dati1||dati2|| 4|||dati1||dati22|| 5|||dati1||dati2||3 tipa tas unikālais buus tas kaukas||| tad: <php $vards='2|||'; $fails=file('dati.txt'); $taspats=fopen('dati.txt','w'); foreach($fails as $line){ if(!strstr($line,$vards)){ fputs($taspats,$line); }} fclose($taspats); ?> izdzēsīs otro līniju 15060[/snapback] tas ir pilniigi neefektiivi. nezinu, kam tur tie identifikatori vajadziigi, bet pat ja vinjus atstaaj: taa kaa strstr darbojas leenaak par strpos, mees varam aizmirst par to, ka identifikatoriem ir jaabuut unikaaliem un aizvietot if(!strstr($line,$vards)){ ar if(strstr($line,$vards)!==0){ Link to comment Share on other sites More sharing options...
dot Posted March 16, 2005 Author Report Share Posted March 16, 2005 $nr - rindas nummurs, kura jādzēš. Pirmās rindas nummurs ir 0. $data = file("dati.txt"); $data_part_1 = array_slice($data,0, $nr); $data_part_2 = array_slice($data, $nr + 1, count($data)); $data = array_merge($data_part_1, $data_part_2); $output = implode("", $data); $f = fopen("dati.txt", "w"); flock($f, LOCK_EX); fwrite($f, $output); flock($f, LOCK_UN); fclose($f); 15041[/snapback] shitais manu praat ir labaakais piemeers, tikai nedzeeshas tieshi tas kas vajadziigs, dzeeshas galiigi kkas cits un to no kaa vajadzeeja atbriivoties paliek. meegginaashu pats kaut kaa pierubiities, bet ceru ka te arii kaads paliidzees. Link to comment Share on other sites More sharing options...
Recommended Posts