Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
dvprog_09 [2013-01-14 14:14] Daniel Viström |
dvprog_09 [2015-02-11 22:44] Daniel Viström |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Genomgång 7 - Att läsa från och skriva till textfiler ====== | ====== Genomgång 7 - Att läsa från och skriva till textfiler ====== | ||
+ | <php> | ||
+ | /* | ||
Tutorial:\\ | Tutorial:\\ | ||
[[http:// | [[http:// | ||
[[http:// | [[http:// | ||
+ | */ | ||
+ | </ | ||
<code php> | <code php> | ||
<?php | <?php | ||
/* | /* | ||
- | * Genomgång på hur man kan läsa och skriva till och från texfiler. | + | * Genomgång på hur man kan läsa och skriva till och från textfiler. |
* Dessa funktioner öppnar och stänger filerna automatiskt. | * Dessa funktioner öppnar och stänger filerna automatiskt. | ||
* Funktioner som gås igenom för att läsa från textfiler: | * Funktioner som gås igenom för att läsa från textfiler: | ||
Line 23: | Line 27: | ||
// Läser en textfil till en sträng. | // Läser en textfil till en sträng. | ||
$str = file_get_contents(' | $str = file_get_contents(' | ||
- | echo nl2br($str) . '< | + | echo nl2br($str) . '< |
// Läser in en textfil till en array, radbrytning ger ny " | // Läser in en textfil till en array, radbrytning ger ny " | ||
Line 32: | Line 36: | ||
while ($i < count($arr)) { | while ($i < count($arr)) { | ||
$row = explode(':', | $row = explode(':', | ||
- | // print_r($row); | + | // print_r($row); |
- | // Skriver bara ut de som heter Johansson | + | // Skriver bara ut de som heter Svensson |
- | if (trim($row[2]) == 'Johansson') { // trim tar bort radbrytning. | + | if (trim($row[2]) == 'Svensson') { // trim tar bort radbrytning. |
$temp = ' | $temp = ' | ||
- | file_put_contents(' | + | file_put_contents(' |
} | } | ||
$i++; | $i++; |