Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

textarea and linebreaks

  • 16-04-2009 02:25PM
    #1
    Registered Users, Registered Users 2 Posts: 7,516 ✭✭✭


    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, Registered Users 2 Posts: 2,011 ✭✭✭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, Registered Users 2 Posts: 7,516 ✭✭✭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