By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Newline problem "\n"

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.