473,473 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Newline problem "\n"

I'm having a problem getting rid of newlines.

say I have this situation:

$cat = "A nice\n cat";

The "\n" is an escape character which creates a newline right there.

Now, how would I get rid of the newline in that string?

How would I then make that string: "A nice cat" ? without the newline
being there?

Also, another question.

If I have a string, let's say: "The man\nwent to the\tdairy\ryesterday"
Does anybody know of a function or of a way to display or find out the
escaped characters in the string? Something that would point out which
escaped characters were in the string?

The reason that I am asking is because I put a form on a web page and I
want to find out what escaped characters are in the resulting $_POST
variable for one of the fields, for a javascript reason.

Any help is much appreciated.

Nick

Jul 17 '05 #1
3 1960
mudge wrote:
I'm having a problem getting rid of newlines.

say I have this situation:

$cat = "A nice\n cat";

The "\n" is an escape character which creates a newline right there.

Now, how would I get rid of the newline in that string?

How would I then make that string: "A nice cat" ? without the newline
being there?
$cat = str_replace("\n", "", $cat);
Also, another question.

If I have a string, let's say: "The man\nwent to
the\tdairy\ryesterday" Does anybody know of a function or of a way to
display or find out the escaped characters in the string? Something
that would point out which escaped characters were in the string?

The reason that I am asking is because I put a form on a web page and
I want to find out what escaped characters are in the resulting $_POST
variable for one of the fields, for a javascript reason.


How about strpos($cat, "\n");

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2
I can't beleive it. I figured it out.

You see, when you fill in a field in a form and it gets past off to a
$_POST in a php script, both "/n" and "/r" get attatched to each line
break.

The reason I couldn't get rid of the line breaks, was because I was
only replacing "/n" when I also needed to replace "/r" as well.

Thanks

Jul 17 '05 #3
"mudge" <mu****@gmail.com> writes:
I can't beleive it. I figured it out.

You see, when you fill in a field in a form and it gets past off to a
$_POST in a php script, both "/n" and "/r" get attatched to each line
break.

The reason I couldn't get rid of the line breaks, was because I was
only replacing "/n" when I also needed to replace "/r" as well.
Be careful. this may depend on what OS platform your client is on.
All three of Linux, Mac, Windows use differing line termination.

If memory serves; \n, \r\n, \n\r (respectively)

If in the HTTP protocol spec it's required for any client to send \r\n
for EOL, then you may disregard my advice.

HTH

Thanks


--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gregory | last post by:
I am working through the exercises in the book "Learning PHP 5". I am using OS 10.3.7, with Apache, Safari and IE. When I execute the following code, the newline "\n" does not work. The ouput is...
26
by: Chris Potter | last post by:
Hello everyone. I am taking my first course in C and in one of my assignments i need to print out an array that could have anywhere from 0 to 100 positive integers in it (a negative integer is...
11
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed....
6
by: Marty | last post by:
Hi, I would like to replace "\r\n" by "_" within a specific string. I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or...
4
by: Brent | last post by:
Take this string: "---------------------------------------- " (i.e., hyphens followed by a newline ) I thought I could match it simply with this Regex: "-*?\n"
2
by: Karlo Lozovina | last post by:
Consider this short script: --- from time import time, sleep st = time() print 'Start: %f, ' % st, sleep(10) sp = time() print 'Stop: %f, Duration: %f' % (sp, (st - sp))
14
by: stevek | last post by:
Following code does not produce any new lines. Any ideas. echo "This spans\multiple lines. The newlines will be\noutput as well.";
2
by: Juha Nieminen | last post by:
I assume that using '\n' to print a newline is not portable because in some systems newline consists actually of two characters and '\n' is only one. Thus the only portable way of printing a...
2
by: manontheedge | last post by:
I'm getting weird results in my program, and even compile time errors, and I've got it down to the "\n" command I use in "printf()". The program this is happening in deals with multiple processes,...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.