PDA

Click to See Complete Forum and Search --> : Append Text File


lintz
Apr 27th, 2007, 01:37 AM
I've got this line of text I'm trying to append to a text file using the below 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>";


$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:
<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?

kows
Apr 27th, 2007, 01:59 AM
I ran the same script and it worked fine.

also, any reason why you're calling fwrite() twice? this works better:

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.

penagate
Apr 27th, 2007, 05:13 AM
I think you probably have word wrapping on in your editor.

lintz
Apr 28th, 2007, 05:38 PM
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.