spermer_co Posted February 28, 2007 Report Share Posted February 28, 2007 Vajadziigs steidzami diezgan skripts kursh atveers .txt failu ar daudzaam rindinaam un dubultos katri rindinai pirmo vaardu. Piemēram ir rindiņa failā Banaans http://lapa Tad šaj rindiņai vaidzētu pārtapt par Banaans Banaans http://lapa Link to comment Share on other sites More sharing options...
andrisp Posted February 28, 2007 Report Share Posted February 28, 2007 Varbūt nav pats elegantākais variants, bet strādā: <?php $arr = file('fails'); foreach($arr as $k => $v) { $first_word = substr($v, 0, strpos($v, ' ')); $arr[$k] = $first_word.' '.$first_word.substr($v, strpos($v, ' ')); } print_r($arr); ?> Link to comment Share on other sites More sharing options...
spermer_co Posted February 28, 2007 Author Report Share Posted February 28, 2007 (edited) jaa vinsh parveido bet man vajag lai vinsh taja pashaa vai citaa failaa to visu arii saglabaa ar 2 pirmajiem vardiem priekshaa, tikai bez tiem [1] [2] [3] un => vienkaarshi Banaans Banaans http:// Edited February 28, 2007 by spermer_co Link to comment Share on other sites More sharing options...
Exzo Posted March 1, 2007 Report Share Posted March 1, 2007 Kaukā <?blabla[..] foreach($arr as $k => $v) { $first_word = substr($v, 0, strpos($v, ' ')); $output .= $first_word.' '.$first_word.substr($v, strpos($v, ' ')); } $handle = fopen('fails', "w") fwrite($handle, $output); fclose($handle); Link to comment Share on other sites More sharing options...
andrisp Posted March 1, 2007 Report Share Posted March 1, 2007 spermer_co, tie [1] [2] [3] tur bija tikai tāpēc, ka izmantoju print_r(), kas paredzēts masīvu smukai aplūkošanai :). Link to comment Share on other sites More sharing options...
spermer_co Posted March 1, 2007 Author Report Share Posted March 1, 2007 Parse error: syntax error, unexpected T_STRING in C:/blabla/tram.php on line 10 Link to comment Share on other sites More sharing options...
andrisp Posted March 1, 2007 Report Share Posted March 1, 2007 Un ? Kā lai mēs zinām, kura ir 10. rindiņa tavā kodā ? Link to comment Share on other sites More sharing options...
spermer_co Posted March 1, 2007 Author Report Share Posted March 1, 2007 (edited) Kaukā <?blabla[..] foreach($arr as $k => $v) { $first_word = substr($v, 0, strpos($v, ' ')); $output .= $first_word.' '.$first_word.substr($v, strpos($v, ' ')); } $handle = fopen('fails', "w") fwrite($handle, $output); fclose($handle); varbuut no shejienes? fwrite($handle, $output); fclose($handle); Edited March 1, 2007 by spermer_co Link to comment Share on other sites More sharing options...
andrisp Posted March 1, 2007 Report Share Posted March 1, 2007 Nu re - pats kļūdu atradi. Link to comment Share on other sites More sharing options...
spermer_co Posted March 1, 2007 Author Report Share Posted March 1, 2007 bet kaa izlabot .. patiesiibaa man vairak nevajag skriptu shito jo izdariju to manuaali ar ieprieksheja skripta palidzibu bet tikuntaa.. varetu piebeigt vinu Link to comment Share on other sites More sharing options...
andrisp Posted March 1, 2007 Report Share Posted March 1, 2007 Semikols trūkst. Link to comment Share on other sites More sharing options...
spermer_co Posted March 1, 2007 Author Report Share Posted March 1, 2007 hmm es pastijos no cita piemeeram php.net un tur bija taapat fwrite($file, $text); fclose($file); Link to comment Share on other sites More sharing options...
andrisp Posted March 1, 2007 Report Share Posted March 1, 2007 Paskaties rindiņu augstāk. Link to comment Share on other sites More sharing options...
spermer_co Posted March 1, 2007 Author Report Share Posted March 1, 2007 nu jaa taa es sapratu.. pieliku. un kas notiek? Warning: Invalid argument supplied for foreach() in C:\blabla\tram.php on line 3 Link to comment Share on other sites More sharing options...
Stopp Posted March 1, 2007 Report Share Posted March 1, 2007 (edited) Un tagad tikai nesaki, ka tu tiešām nokopēji kodu ar visu <?blabla[..] un neko nemainīji. Iztulkojot kļūdu - neesi padevis pareiza formāta datus (masīvu) foreach funkcijai. Ja tu pats nevari kodā atrast, ko tad tu īsti padod tai funkcijai, tad vismaz iemet šeit kodu, nevis gaidi, kad kāds šeit izpīpēs, kāda tev varētu būt kļūda. edit: džīz... Nupatkā ieraudzīju to 'on line 3'. Skaties otro rindiņu andrisp kodā. Edited March 1, 2007 by Stopp Link to comment Share on other sites More sharing options...
Recommended Posts