-
Append Text File
I've got this line of text I'm trying to append to a text file using the below code.
HTML Code:
$TextToAdd = "<li>SDG gave a Lighten alert.</li><li>CPB gave a Pyramid alert.</li><li>OKN gave a Pyramid alert.</li><li>SHR gave a Lighten
alert.</li><li>TRU gave a Pyramid alert.</li><li>BEN gave a Buy alert.</li><li>NAB gave a Sell alert.</li>";
PHP Code:
$linebreak = "\r\n";
//name of file to add info
$filename = "test file.txt";
//Open file for append
$open_file = fopen($filename, 'a');
//add to file
fwrite($open_file, $TextToAdd);
//add line break
fwrite($open_file, $linebreak);
//Close file
fclose($open_file);
However, when I open the file the text has been split up over several lines and looks like this?? :confused:
HTML Code:
<li>SDG gave a Lighten
alert.</li><li>CPB gave a Pyramid
alert.</li><li>OKN gave a Pyramid
alert.</li><li>SHR gave a Lighten
alert.</li><li>TRU gave a Pyramid
alert.</li><li>BEN gave a Buy
alert.</li><li>NAB gave a Sell
alert.</li>
Why is this happening and how can I ensure the text is displayed on 1 line of the text file?
-
Re: Append Text File
I ran the same script and it worked fine.
also, any reason why you're calling fwrite() twice? this works better:
PHP Code:
fwrite($open_file, $TextToAdd . $linebreak);
what text editor are you opening this in? there's like, no possible way for line breaks to just randomly appear out of no where. you're either leaving something out when you're processing for $addtotext, or you are using a weird text editor that is doing something wrong.
-
Re: Append Text File
I think you probably have word wrapping on in your editor.
-
Re: Append Text File
My error :blush: ...... when I was reading the signal type (Pyramid, Lighten ec...) each had a line break after it so that is why in my output text file there was a line break after each signal.....Thanks.