Results 1 to 4 of 4

Thread: Append Text File

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Append Text File

    I think you probably have word wrapping on in your editor.

  4. #4

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved Re: Append Text File

    My error ...... 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width