blondine Posted May 9, 2010 Report Share Posted May 9, 2010 (edited) izmantojot fpassthru.. Edited May 26, 2010 by blondine Quote Link to comment Share on other sites More sharing options...
Леший Posted May 9, 2010 Report Share Posted May 9, 2010 Nolasi faila saturu, sadalot ar delimiteru \n, sanāks array, kur [0] elements būs header, bet visi pārējie - teksts. Salīmē tos vusus teksta elementus ([1]...[n]) vienā rindā, paņem noteiktu simbolu skaitu. Quote Link to comment Share on other sites More sharing options...
Леший Posted May 10, 2010 Report Share Posted May 10, 2010 Resource id #.. ir visdrīzāk, neapstrādāts MySQL rezultāts. Laikam esi aizmirsusi kaut kur ielikt mysql_result, vai mysql_fetch_*** Quote Link to comment Share on other sites More sharing options...
blondine Posted May 10, 2010 Author Report Share Posted May 10, 2010 godigi sakot sajaa piemera nav nekada sakara ar mysql, jo viss notiek tikai ar faila apstradi... Quote Link to comment Share on other sites More sharing options...
Леший Posted May 10, 2010 Report Share Posted May 10, 2010 Tad tas Resource ir faila atvēršanas rezultāts. Iespējams, to dod funkcija fopen. Paprovē izmantot file_get_contents(). Quote Link to comment Share on other sites More sharing options...
blondine Posted May 10, 2010 Author Report Share Posted May 10, 2010 (edited) viss itkaa butu labi, bet file_get_contents() panem ari $header tekstu - samet visu vienaa kaudze... bet ar explode "\r\n" neizdodas atdalit $header un izvadit: $section = file_get_contents($path, NULL, NULL, 0, 500) $size = 500; if ($section = file_get_contents($path, NULL, NULL, 0, 500)) { $section = explode("\r\n", $post); for($i = 0; $i < $size; $i++) { echo $section[$i].' '; } } bet atkal tas Resource id #, laikam izvades sintakse un princips nav pareizs.. nav ideju! Edited May 10, 2010 by blondine Quote Link to comment Share on other sites More sharing options...
Леший Posted May 10, 2010 Report Share Posted May 10, 2010 Tak palasi savu kodu! Kāpēc uzreiz pēc $section = file_get_contents() tu pārraksti to $section? Quote Link to comment Share on other sites More sharing options...
php newbie Posted May 10, 2010 Report Share Posted May 10, 2010 (edited) $size = 500; if ($section = file_get_contents($path, NULL, NULL, 0, 500)) { $section = explode("\r\n", $post); for($i = 0; $i < $size; $i++) { echo $section[$i].' '; } } viss ir tik dīvains... sākumam no kurienes ir $post mainīgais? tur nevajadzētu būt $section(faila saturs)? un $section = file_get_contents($path, NULL, NULL, 0, 500) $section sanāk string t.k. file_get_contents atgriež stringu un tad $section = explode("\r\n", $post); tam string tipa mainīgajam mēģina piešķirt jau array t.k. explode atgriež array varbūt php tā drīkst darīt, bet nu man neizskatās smuki Edited May 10, 2010 by php newbie Quote Link to comment Share on other sites More sharing options...
Леший Posted May 10, 2010 Report Share Posted May 10, 2010 Kods joprojam ir perverss, bet for($i = 1; $i < $size; $i++) laikam strādās. Quote Link to comment Share on other sites More sharing options...
php newbie Posted May 10, 2010 Report Share Posted May 10, 2010 es nevaru saprast tavu loģiku :( es darītu tā: // nolasa faila saturu $filecontent_str = file_get_contents($path, NULL, NULL, 0, $size); // explode sadala string saturu kā masīvu $filecontent_arr = explode($delimiter, $filecontent_str) tad $filecontent_arr[0] būtu header un viss parējais($filecontent_arr[1], $filecontent_arr[2], $filecontent_arr[3]...) - saturs un ciklam jāizpildas nejau 500 reizes, bet tik cik garšs ir masīvs t.i. sizeof($filecontent_arr) Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted May 10, 2010 Report Share Posted May 10, 2010 (edited) pagaidam jaizdomaa kaa varetu astat veselu pedejo vardu..hmm varbut kadam ir idejas par to un koda optimizaciju.. Jaa.. izmanto DB .. kur viena laukaa ir haideris nakamaja pats teksts.. Ieguvumi buus LJOTI daudz.. Ja liels apmekletaju skaits, tad peec teksta pievienosanas uzgenere HTML iskus dokumentus .. Buus gan optimali, gan skaisti etc.. labumi ... Edited May 10, 2010 by Grey_Wolf Quote Link to comment Share on other sites More sharing options...
marcis Posted May 10, 2010 Report Share Posted May 10, 2010 $delimiter = "\r\n"; $contents = file_get_contents($filename); $contents = substr($contents, strpos($contents, $delimiter)+strlen($delimiter), 500); // nogriežam headeri un beigas $contents = substr($contents, 0, strrpos($contents, ' ')); // nogriežam visu, kas seko pēc pēdējās atstarpes (pieņemot, ka ar to beidzas pēdējais veselais vārds) Quote Link to comment Share on other sites More sharing options...
m8t Posted May 10, 2010 Report Share Posted May 10, 2010 file_get_contents() [function.file-get-contents]: Filename cannot be empty in...uutt. Quote Link to comment Share on other sites More sharing options...
php newbie Posted May 10, 2010 Report Share Posted May 10, 2010 varu pārtulkot kļūdu: funkcija gaidija pirmo parametru stringu, bet tu iebaroji resource Quote Link to comment Share on other sites More sharing options...
briedis Posted May 14, 2010 Report Share Posted May 14, 2010 p.s. gribēju vel paturpinat, izvadot tekstu - paradas kaut kads simbols.... kādi varētu but risinajumi, uz localhost viss kartiba.. Paša sākumā? Vēlams pārsaglabāt failu uz Utf-8 WITHOUT BOM formātu. Tas ir tas BOM simbols, man liekas.. 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.