File Manipulation Help
Moderator: General Moderators
File Manipulation Help
If I want to remove just the first line and the last line in a file, how would i do that? I also want to shift all the file contents up a line and remove the last blank line ( or would it automatically do that?) If anyone can help at all, I'd be most greatful. Thanks.
You can do something like this if you like
This does not actually remove anything from anywhere. It just does not write it back there.
Code: Select all
<?php
//"remove" the first and last
$file="test.txt";
$lines=file($file);
$new_data="";
for($i=1; $i<count($lines)-1; $i++){
$new_data.= $lines[$i];
}
//Trim the empty line
$new_data=trim($new_data);
$open=fopen($file, "w");
fwrite($open, $new_data);
fclose($open);
?>well... that's not exactly what i was needing. however, i figured out how to do it by :
Code: Select all
str_replace('this_string','',$fileContent);