Writing line breaks to text file - getting little squares

Posted on 2004-04-27
Last Modified: 2013-12-12
Hi, I am using the script:

$inputString = "Customer\tContact\tStreet\tCity\tProvince\tPostal code\tPhone\tFax\tE-mail\tWeb site\tMemo\n";
$fp = fopen("SAtemp/temp.txt", "w+") or die("Couldn't create new file");
fwrite( $fp, $inputString );

to write text to a file, then to send it by email I use:

 include('class.Email.php');   //this class is found at:

  $NewEmail = new Email($compName." <".$rcpemail.">", $email, $subject);
  $NewEmail->TextOnly = true;
  $NewEmail->Content = "This email has been sent to you through the ". $compName." Contact form at ".$compURL."\r\n\r\nMessage from: ".$customer."\r\nReply email address: ".$email."\r\n Website address: ".$website."\r\nContact Name: ".$contact."\r\nAddress: ".$street."\r\nCity: ".$city."\r\nProvince: ".$province."\r\nPostal Code: ".$postalcode."\r\nPhone Number: ".$phone."\r\nFax Number: ".$fax."\r\n\r\n=================== Message Text Below ====================\n\n".stripslashes($memo);

//** send a copy of this file in the email.

  $NewEmail->Attach("SAtemp/temp.txt", "text/plain");

Now, the only problem I have is when I open the text file I see a little square at the end of the line instead of the line break.  Any suggestions, please?
Question by:earthman100

Expert Comment

ID: 10934619
Are you getting...

some stuff here[]some more stuff[]and yet another line

Or are you getting...

some stuff here[]
some more stuff[]
and yet another line

If it's the second one try removing all the instances of \r and just leave the \n's in.

Alternatively, try replacing "text/plain" with "text/html".
LVL 32

Expert Comment

ID: 10935566
You can try using Ln() Line break functio, instead...

$NewEmail->Content = "This email has been sent to you through the ". $compName." Contact form at ".$compURL.Ln().Ln()."Message from: ".$customer.Ln()."\rReply email address: ".$email.Ln()." Website address: ".$website.Ln()."Contact Name: ".$contact.Ln()."Address: ".$street.Ln()."City: "................and so on....

If i was wrong somewhere, you can well see and use this tutorial...

Author Comment

ID: 10935717
Actually I am getting it in the text file I am generating:

$inputString = "Customer\tContact\tStreet\tCity\tProvince\tPostal code\tPhone\tFax\tE-mail\tWeb site\tMemo\n";

at the end.  Just a single square, with no line break.  The others work fine.
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

ID: 10935875
I tried text/html and still get the same result in the txt file.  Any further suggestions would be appreciated!  Thanks!

Author Comment

ID: 10935911
ooop, I got it.  I had tried \n\r and it didn't work, but then I discovered I needed to put \r\n instead.  YAY!

found it at:

Thanks y'all anyhoo.

Accepted Solution

PashaMod earned 0 total points
ID: 10971691
Closed, 500 points refunded.
Community Support Moderator

Expert Comment

ID: 21931220
I had the same issue,

the suggestion above,

(ID:10935911  Author:earthman100  Date:04.27.2004 at 11:13PM PDTAuthor Comment)



Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question