Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Insert break

  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    138
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Insert break

    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.

    Code:
    $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>
    				</body></html>";
    
    
    fwrite ($profile, $doc_content);
    Since it is a multiline text area, MS Word ignores the breaks in the text area.

    so if i put:

    Code:
    Since it 
    is a multiline 
    text area.
    It shows as

    Code:
    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?

    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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>".

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    138
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you! nl2br() work perfectly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •