View Full Version : Insert break

09-02-2008, 06:22 PM
What I am trying to do is simple. When I get the data from a text area in a textbox in a form , here is what I am doing to put it in a doc file.

$resume = $_POST['resume'];

$profile = $_POST['lname']."_"."Profile".$filedate.".doc";
$profile = fopen($profile, "w") or die( "Error opening file" );

flock ($profile, LOCK_EX);

$doc_content = "<html><head></head><body>
<b>Resume: </b> <br> $resume <br>

fwrite ($profile, $doc_content);

Since it is a multiline text area, MS Word ignores the breaks in the text area.

so if i put:

Since it
is a multiline
text area.

It shows as

Since it is a multiline text area.

I think the way to get that is to take it (textarea) in an array and then append a break tag (<br>) at the end of each line. Am I in the right direction? If so, how do i do it?


09-02-2008, 06:36 PM
It's generally not ideal to add the <br>s in with the text because it makes the text less flexible. As long as the line breaks are in there, you can use PHP's nl2br() function to add the <br>s whenever the text is displayed. If the <br>s are part of the text, then you'll have to strip them out when you have to put the text back into a textarea (to edit the text, for example).

But in your case where you're using Word, including the <br>s in the text may be your best option. I would use the str_replace() function and replace "\n" with "<br>".

09-02-2008, 07:19 PM
Thank you! nl2br() work perfectly.