Add new line to end of text file

5 posts by 2 authors in: Forums > CMS Builder
Last Post: June 15, 2010   (RSS)

By eduran582 - June 13, 2010 - edited: June 13, 2010

Hi all,
I'm having a problem adding a new line to the end of a text file that does not have a new line (and optionally adding a new blank line). Some of the variable values have quotes around them and some not.

Here's the line I want to add:
$Data = '"'.$oneVariable.'",'.$anotherVariable."\r\n"; //"oneThing",12345
I've tried using '"\r\n"'.$aVariable."\r\n" to create a new line first but that doesn't work either.

I know this is probably something simple but at this point, "I can't see the forest for the trees" and am getting lost.

TIA,
Eric

Re: [eduran582] Add new line to end of text file

By Jason - June 14, 2010

Hi,

What is being outputted to the text file? Do the variables output correctly, just not the blank line at the end?

If you could attach the .php file you're using and a copy of the text file it produces, I can take a closer look.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [eduran582] Add new line to end of text file

By Jason - June 15, 2010

Hi Eric,

Not a problem, email them to jason@interactivetools.com and I'll take a look.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [eduran582] Add new line to end of text file

By Jason - June 15, 2010

It seems that you create 2 strings. One called $tData on line 105 (this has \r\n at the beginning and the end of the string) and one called $Data on line 121 (this doesn't have \r\n). $tData only seems to be used to make a comparison checking to make sure the same line isn't being outputted twice. $tData is never actually outputted to the file, only $Data is. What I would suggest trying is adding \r\n to the end of $Data since this is the variable that's written to the file. Also, I would only put it at the end. If you put it at the beginning and the end, you'll be putting a blank line before and after the line you're writing (if this is what you want, then put it before and after).

I hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/