Created
March 11, 2013 12:38
-
-
Save ChristianGaertner/5133951 to your computer and use it in GitHub Desktop.
This function just removes a specific line of a text document. Pass the path to the file or an URL to the file and the line you want to remove. The function will return the new file which you can save or work with it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeLine ($file, $lineToRemove) { | |
$data = file_get_contents($file); | |
$lines = explode(PHP_EOL, $data); | |
$lineNo = 1; | |
foreach($lines as $line) { | |
$linesArray[$lineNo] = $line; | |
$lineNo++; | |
} | |
unset($linesArray[$lineToRemove]); | |
return implode("\n", $linesArray); | |
} | |
removeLine ("../dir/to/file.txt", 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment