Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to File With Line breaks?

Status
Not open for further replies.

locell

Programmer
Joined
Oct 25, 2003
Messages
1
Location
US
I'm trying to write to a file and it's working except there are no
line breaks everything is on the same line!!!

!!!!!!!!CAN SOME ONE PLEASE HELP ME!!!!!!!!!

Here is the Code:



$content = "";
$content.= "AmeriPlan Sign-up Request\n\n";
$content.= "$first_name $middle_initial $last_name, has requested to be\n";
$content.= "Enrolled in the Dental Care Program.\n\n";
$content.= "$first_name $middle_initial $last_name\n";
$content.= "Address: $mail_address ";
if ($apt_num) {
$content.="$apt_num";
}
$content.= "\n";
$content.= "$city, $state $zip_1-$zip_2\n\n";
$content.= "D.O.B.: $dob_mm/$dob_dd/$dob_yyyy\n";
$content.= "Social Security #: $social_1-$social_2-$social_3\n";
$content.= "Sex: ";
if($sex_m) { $content.="Male"; } else { $content.="Female"; }
$content.= "\n";
$content.= "Telephone #: ($tel_1) $tel_2-$tel_3\n";
$content.= "E-Mail: $email\n\n";
$content.= "Applicant's Employer: $app_employ\n\n";
$content.= "I want my materials in:\n";
$content.= "English: ";
if($mat_english) { $content.="Yes\n"; } else { $content.="No\n"; }
$content.= "Spanish: ";
if($mat_spanish) { $content.="Yes\n"; } else { $content.="No\n"; }
$content.= "\n\n";
if ($fam_member_first || $fam_member_first2 || $fam_member_first3 ||
$fam_member_first4 || $fam_member_first5) {
$content.="Household Members\n\n";
if($fam_member_first) {
$content.="$fam_member_first $fam_member_last ($fam_member_dob)\n";
}
if($fam_member_first2) {
$content.="$fam_member_first2 $fam_member_last2 ($fam_member_dob2)\n";
}
if($fam_member_first3) {
$content.="$fam_member_first3 $fam_member_last3 ($fam_member_dob3)\n";
}
if($fam_member_first4) {
$content.="$fam_member_first4 $fam_member_last4 ($fam_member_dob4)\n";
}
if($fam_member_first5) {
$content.="$fam_member_first5 $fam_member_last5 ($fam_member_dob5)\n";
}
}
$content.="\n\n";
if ($ref_name || $ref_name2 || $ref_name3 || $ref_name4 || $ref_name5) {
$content.="Referrals:\n\n";
if ($ref_name) {
$content.="$ref_name ($ref_num_one) $ref_num_two\n";
}
if ($ref_name2) {
$content.="$ref_name2 ($ref_num_one2) $ref_num_two2\n";
}
if ($ref_name3) {
$content.="$ref_name3 ($ref_num_one3) $ref_num_two3\n";
}
if ($ref_name4) {
$content.="$ref_name4 ($ref_num_one4) $ref_num_two4\n";
}
if ($ref_name5) {
$content.="$ref_name5 ($ref_num_one5) $ref_num_two5\n";
}
}
$content.="\n\n";


$file_arch = "/home/whutch/public_html/appz/_logs/_signups/" . $first_name . " " . $last_name . ".lds";
$signup = fopen($file_arch, 'w+') or die("Could not create file:\n $file_arch");
fputs($signup, "$content")
fclose($signup);

I'm using "\n" but everything is on the same line!!!
 
yup,
\n\n must change to \r\n...

Known is handfull, Unknown is worldfull
 
PHP Manual:

Note: Different operating system families have different line-ending conventions. When you write a text file and want to insert a line break, you need to use the correct line-ending character(s) for your operating system. Unix based systems use \n as the line ending character, Windows based systems use \r\n as the line ending characters and Macintosh based systems use \r as the the line ending character.
...
Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.
...
For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen().

Again, for portability, it is also strongly recommended that you re-write code that uses or relies upon the 't' mode so that it uses the correct line endings and 'b' mode instead.

As of PHP 4.3.2, the default mode is set to binary for all platforms that distinguish between binary and text mode. If you are having problems with your scripts after upgrading, try using the 't' flag as a workaround until you have made your script more portable as mentioned above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top