extra lines in text file function str_replace
Posted: Tue Jan 18, 2011 1:05 am
Below is my code:
Here is my problem:
This code is inserting a line of text (encoded urls) from one text file to another. This part works correctly, but the problem that I'm having is it's also inserting an empty line break in the new file, every time it moves the line of text to the new file. I need it to just insert the lines, without extra line breaks. Help is needed, and greatly appreciated!
Code: Select all
function TransferLine($link,$fromfile,$tofile)
{
if(file_exists($fromfile) && file_exists($tofile))
{
$holdcontents = file_get_contents($fromfile);
$holdcontents2 = str_replace($link, "", $holdcontents);
$holdcontents2 = str_replace("\n", "\n", $holdcontents2);
file_put_contents($fromfile, $holdcontents2);
$fileContents = $link . PHP_EOL;
file_put_contents($tofile, $fileContents, FILE_APPEND);
}
else
{
$string = "FileNotExist";
};
return $string;
}
This code is inserting a line of text (encoded urls) from one text file to another. This part works correctly, but the problem that I'm having is it's also inserting an empty line break in the new file, every time it moves the line of text to the new file. I need it to just insert the lines, without extra line breaks. Help is needed, and greatly appreciated!