Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

textarea and linebreaks

Options
  • 16-04-2009 2:25pm
    #1
    Registered Users Posts: 7,518 ✭✭✭


    I'm writing a script to take in xml from a text area. The basics are working fine but one thing I'm finding is that if I copy and paste the xml in from some text editors (e.g. gedit) an extra line break is added after each line when I return it to the page after processing with PHP, however if I type it in it works correctly

    i.e. if I type in it, after return I get

    <tag1>
    <tag2>
    </tag2>
    </tag1>

    but if I copy and paste after returning I get

    <tag1>

    <tag2>

    </tag2>

    </tag1>


    I've taken a look and it only seems to happen if the editor you copy and paste from uses \r\n for a newline. When it's returned back to the browser I get \n\n back instead of the \r\n

    If input it from an editor that just uses \n it works correctly


Comments

  • Registered Users Posts: 2,031 ✭✭✭colm_c


    Surely the line breaks in the XML shouldn't make any difference? Isn't there a remove whitespace option in some of PHP XML libraries?

    Anyway the linebreaks are down to how windows and the various unix flavours have different line return/break characters. Some of the editors are a little more cross OS compatible and stick in extra characters for line breaks.


  • Registered Users Posts: 7,518 ✭✭✭matrim


    The main problem I'm seeing is that I take in to the XML parser and if there is an error return it to the user so they can edit it. When I return it from their errors it doesn't look correct.

    I can still do the xml parsing if it's like this, it's just returning it to the user that causes a problem.

    I just find it strange that it's actually returning different to what should be passed in to it. I.e the \r\n being changed to \n\n that I mentioned above

    And is there a way around it without running it through a str_replace to replace all occurrences of \n\n with \n


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Have you tried the different settings for the wrap="virtual|physical|off|soft|hard"

    Virtual/Soft forces the words to wrap once inside the text area but when the form is submitted, the words will no longer appear as such (Line breaks will not be added).

    Physical/Hard wraps the words inside the text box and places line breaks at the end of each line so that when the form is submitted it appears exactly as it does in the text box.

    Off sets a textarea to ignore all wrapping and places the text into one ongoing line.


Advertisement