You could read one line at a time, remove the " , and save file.
Reading one line at a time will be a lot less memory-intensive as compared to loading all the file at once. So, you can process any size of .txt
files, limited only by your computer speed.
Note: I assume that you are using Local Web Server
. Any shared hosting may not allow you to over-ride the 30 second max execution time limit. I recommend using this code on local XAMPP server.
<?php
set_time_limit(0); //To remove the max-execution time limit
$file_from = "foo.txt"; //File containing all the text
$file_to = "bar.txt"; //New File containing all the modified text
//open both files
$fp_source = fopen($file_from, "r") or die("Couldn't open ".$file_from);
$fp_dest = fopen($file_to, 'a+') or die("Couldn't open ".$file_to);
while (!feof($fp)) { //Continue loading domains till the end of file
$line = fgets($fp, 1024); //load one line at a time
$line = trim($line, '"'); // remove the first & last "
fwrite($file_to, $line); // save text in new file.
}
fclose($file_from); //close the handles
fclose($file_to); //close the handles
?>
The above code will replace all the " appearing at the first & last position in a string, where each string is differentiated from another by a new-line character.
If the " appear in the middle of the string, then you could replace this line
$line = trim($line, '"'); // remove the first & last "
with:
$line = str_replace('"', "", $line); // remove all the "
Although you have tagged the question as PHP
, but if it is only one file, or few files, I would recommend using the search & replace functions of any desktop text editor, like Notepad++ etc..