Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've run into these "ending" problems with the input from Web browser "textarea" form boxes with browsers running on different platforms -- on say Windows, Linux and Macintosh.

In a form textarea box most Windows browsers (esp. MS IE) after an "enter" or "return" produce a lfcr, on Linux just a lf, and on a Mac browser just a cr (since each plaform developers had differing notions of what constitutes a line break).

Below is the rather inelegant code I used then to display the results on the browser screen (which being HTML wants a <br>, and in the file system of the UNIX box the data were being saved to, which whats a '\n' or lf.

$phrases was the return parameter from a browser textarea box which could have one or more lines with endings generated by the "enter" key.

# Account for differences in browser returns # Replace \r\n, \r, or \n with <br> $lf = chr(10); $cr = chr(13); $phrases =~ s/$lf/<br>/g; $phrases =~ s/$cr/<br>/g; # In case you were on Windows and not UNIX nor MAC, # now have two <br>'s rather than one $phrases =~ s/<br><br>/<br>/g; # Show $html_phrases in text box of browser $html_phrases = $phrases; # Fix $phrases for storage in UNIX file $phrases =~ s/<br>/\\n/g;
Must be an easier way, but this got the list in $phrases displayed properly in the browser, and saved with a single "\n" for line endings regardless of which browser it came from.

Live in the moment

In reply to Re: Where are these newlines coming from? by Speedy
in thread Where are these newlines coming from? by jerrygarciuh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-06-23 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.