I dont often use files, but what I need to do is open, read and right to a file which I use w+ for, but thats not the question.
The question is I need to be able to open the file, parse the data so I can display it as an array, then edit or delete sections of the file.
Any thoughts or suggestions?
Much appreciated.
Using files
Moderator: General Moderators
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
Use file() function if you want to read line by line so...
Use str_replace() to change stuff in the file. Check out the manual for details.
Code: Select all
<?php
$file = file("stuff.php"); // No need for fopen I don't think..
foreach($file as $line_num => $line_data){
// Do you stuff
}
?>-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
This will work with text files too wont it?RadixDev wrote:Use file() function if you want to read line by line so...Use str_replace() to change stuff in the file. Check out the manual for details.Code: Select all
<?php $file = file("stuff.php"); // No need for fopen I don't think.. foreach($file as $line_num => $line_data){ // Do you stuff } ?>
And a "[" can be removed from the file contents as well I assume?
Yep file() works with any kinds of files.
to replace [ with something different (space):
to replace [ with something different (space):
Code: Select all
<?php
$file = file("stuff.txt");
$newfile = "";
foreach($file as $line_num => $line_data){
$newfile .= str_replace("ї"," ",$lin_data);
}
?>