?
Solved

CGI / Perl remove new line character when printing to file.

Posted on 2004-10-16
5
Medium Priority
?
29,251 Views
Last Modified: 2013-12-25
I have an HTML textarea box that I want to save the input from into a text file.

Instead of printing each 'Enter /return' on a new line I want it on the same line with <br> printed instead.

I am using this at the moment but it doesn't quite work how I'd like;

$input =~ s/\n/<br>/g;

Example:
Input:

This
is

input.

Currently saves as:
This
<br>is
<br>
<br>input.

But I want it like this:

This<br>is<br><br>input.



If you get what I mean, is this possible?

Many Thanks, S-P.
0
Comment
Question by:Sparky-Plug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
nicholassolutions earned 260 total points
ID: 12331383
Try this:
$input =~ s/\r?\n/<br>/g;
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 260 total points
ID: 12331916
$input =~ s/[\r\n]/<br>/g;
0
 

Author Comment

by:Sparky-Plug
ID: 12331968
Many Thanks, Both work equally well. Points will be halved between you.

Incidentally, what is the difference between New Line and Carriage Return?


Thanks again, S-P.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12331976
> .. difference between New Line and Carriage Return?
read verbatim :-)
0
 
LVL 15

Expert Comment

by:nicholassolutions
ID: 12333263
carraige return \r means 'go back to the beginning of the line'
newline \n means 'go to a newline'

have a look here for a full explanation:
http://en.wikipedia.org/wiki/Newline
http://www.cdf.utoronto.ca/~csc209h/winter/tut/line-endings.html
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question