Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
dvprog_09 [2015-02-11 22:43] Daniel Viström |
dvprog_09 [2019-12-06 16:09] Daniel Viström |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Genomgång | + | ====== Genomgång - Att läsa från och skriva till textfiler ====== |
<php> | <php> | ||
Line 20: | Line 20: | ||
| | ||
*/ | */ | ||
- | include(' | + | include ' |
// Skriver till en textfil. Finns inte filen skapas den. FILE_APPEND gör att innehåll läggs till och inte skrivs över. | // Skriver till en textfil. Finns inte filen skapas den. FILE_APPEND gör att innehåll läggs till och inte skrivs över. | ||
file_put_contents(' | file_put_contents(' | ||
- | // Läser en textfil till en sträng. | + | $textfil = ' |
- | $str = file_get_contents(' | + | // Läser en textfil till en sträng. |
- | echo nl2br($str) . '< | + | $str = file_get_contents($textfil); |
+ | 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 " | ||
+ | // Varje rad i filen har följande format: | ||
$arr = file(' | $arr = file(' | ||
// print_r($arr); | // print_r($arr); | ||
Line 45: | Line 47: | ||
} | } | ||
- | include(' | + | include ' |
</ | </ | ||