简体   繁体   中英

PHP variable concatenation and text file line breaks

My php variables are like

$boothsizetopges = "CHILDREN'S CLUB MARCH 2013
EHIBITING COLLECTION NAME: $company
BOOTH SIZE: $booth_size
"; 

$companyinfo = "
CONTACT INFORMATION
EXHIBITING COLLECTION NAME: $company
BOOTH NUMBER: $booth
CONTACT: $contact
BOOTH SIZE: $booth_size
CONTACT CELL: $contact_cell
CONTACT EMAIL: $email
STREET ADDRESS: $street
CITY, STATE, ZIP: $city ";

$message = $boothsizetopges . $companyinfo ;

and my code for writing $message to a .txt file is

$myFile = "exfiles/".str_replace(" ","-",$_POST['companyname'])."_".time().".txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $message;
fwrite($fh, $stringData);
fclose($fh);

Here my problem is in .txt file output is printing in a single line without line breaks.. But in mails the data is coming fine in each line.

Need help...

Are you opening the text file in Windows? If so you may be encoding unix-style line breaks (\\n) when you need to use Window's style (\\r\\n). As a simple test add to the end of your first code block:

$message = str_replace("\n", "\r\n", $message);

Generally though, you just want to stick with unix-style (IMHO)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM