473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Removing newline characters

How would you remove newline characters from a string?

I tried

str_replace("\n", "", $string);

But that doesn't work.

Jul 17 '05 #1
2 58149
you also need to remove \r from the string.
(on windows, newline is \r\n, on *nix it's just \n, but a windows client
will send \r\n, and on older macs I think newline was just \r but I can't
remember for sure.)
"Amit Varia" <sp**@amitvaria.com> wrote in message
news:bu**********@geraldo.cc.utexas.edu...
How would you remove newline characters from a string?

I tried

str_replace("\n", "", $string);

But that doesn't work.

Jul 17 '05 #2
"Amit Varia" <sp**@amitvaria.com> wrote in message
news:bu**********@geraldo.cc.utexas.edu...
How would you remove newline characters from a string?

I tried

str_replace("\n", "", $string);

But that doesn't work.


as was posted there is also the \r on some files or \r\n, try this:

// for end of line (or begining)
$string = trim($string);

// from everywhere
$string = str_replace("\n", "", $string);
$string = str_replace("\r", "", $string);

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3

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

Similar topics

1
by: pmud | last post by:
Hi, Through our ASP.NET website, when i complete the order I get the error,"Redirect URI cannot contain newline characters. " Any idea why its doing that? -- pmud
2
by: John Salerno | last post by:
If I read a string that contains a newline character(s) into a variable, then write that variable to a file, how can I retain those newline characters so that the string remains on one line rather...
3
by: Thomas | last post by:
Hi All, i am getting this error once i submit my page to a payment gateway and when it returns the reponse back. Redirect URI cannot contain newline characters. Description: An unhandled...
3
by: Matthew Crouch | last post by:
I just used FileZilla (on windows) to download a site for testing in IE, and it seems a couple of newline characters are added to all the php scripts. This isn't much of a problem until I get to...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
3
by: mobil | last post by:
Hi guys i m trying out newline characters and to clean them up a\n\n\n\n\n\n\n\n\nsss\n\n\n\n\n\n\n\n\n\n\nvvvv\n\n\n\nvsa\n\n\n\nasf \n\nafs hello guys im trying to replace...
0
by: rafficabdullah | last post by:
I need to select the records containing newline characters in them.The data may contain tab and spaces that should not come in the output.This can be done with regexp_like in oracle in 10g.but i...
1
by: JB | last post by:
Hi All, I'm writing XML in VB.NET 2005 using the System.Xml.XmlWriter class. It's all working fine but I'd like to remove a few NewLine characters. For instance if I use the following code:...
5
by: alex21 | last post by:
I am trying to write a function for determining the data type of columns in a delimited file. However my function is not detecting a newline and exiting the loop after the end of the first line. ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.