Jump to content
php.lv forumi

Datu Nolasīšana No *.txt, *.dat U.c Failiem.


Little_Hacker

Recommended Posts

Ka lai uztaisa PHP skriptu, kas nolasa no vienkaarsha texta faila informaaciju kas izskataas ~ shaadi:

a | b | c

a2 | b2 | c2

a3 | b3 | c3

un izvada shaadaa seciiba:

a3 :: b3 :: c3

a2 :: b2 :: c2

a :: b :: c

:) Tjipo vajag lai nolasa failu no otras puses ;) Es piem izmantoju shaadu skriptu, bet vinsh nolasa datu failu un izvada informaaciju taadaa pashaa seciibaa kaada taa ir ieksh datu faila.

<code><font color="#000000">

<font color="#0000CC"><?
$fails </font><font color="#006600">= </font><font color="#0000CC">file </font><font color="#006600">(</font><font color="#CC0000">"datufails.txt"</font><font color="#006600">);
while (</font><font color="#0000CC">$val </font><font color="#006600">= </font><font color="#0000CC">each </font><font color="#006600">(</font><font color="#0000CC">$fails</font><font color="#006600">)) {
</font><font color="#0000CC">$mas </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/explode]explode[/url]</font><font color="#006600">(</font><font color="#CC0000">"|"</font><font color="#006600">,</font><font color="#0000CC">$val</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">]);
print (</font><font color="#CC0000">"<tr><td><b>$mas</font><font color="#006600">[</font><font color="#CC0000">0</font><font color="#006600">]</font><font color="#CC0000"></b> :: $mas</font><font color="#006600">[</font><font color="#CC0000">1</font><font color="#006600">]</font><font color="#CC0000"> :: $mas</font><font color="#006600">[</font><font color="#CC0000">2</font><font color="#006600">]</font><font color="#CC0000"></td></tr>n"</font><font color="#006600">);
}
</font><font color="#0000CC">?>
</font>
</font>
</code>

Link to comment
Share on other sites

Ja stringi teff būs vienmēr sadalīti ar | un nevajadzēdu boldot pirmo fīču, varētu uztaisīt kaut ko tādu:

$in=file('text.dat');

$in=array_reverse($in);

$in=join('</td></tr><tr><td>',$in);

$in=str_replace('|',' :: ',$in);

echo '<tr><td>'.$in.'</td></tr>';

Link to comment
Share on other sites

×
×
  • Create New...