473,662 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 58170
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.u texas.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.u texas.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
4996
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
5664
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 than spans multiple lines? Example: In a CGI script, I'm reading the address field from an HTML form. Almost always the person will press ENTER so they can enter a second or third line. If I then want to write all the field values of this form...
3
8159
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 exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
3
1818
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 my AJAX stuff, where I have to include a couple of scripts before setting the xml content-type header. All the scripts are also double-spaced, which I suspect is the same issue Anyone seen this?
16
38611
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 into the buffer ?
3
1663
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 \n\n\n\n\n\n\n\n\n with \n thanks for help
0
1196
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 need this in 9i.Can any one help me in this Many Thanks in Advance Raffic
1
4814
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: Writer.WriteStartElement("Name") oObject.WriteXml(Writer) 'This object writes it's ow Writer.WriteEndElement("Name")
5
3102
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. * 'del_2' is equal to a new line character, i have tested this using a small bit of code if del_2 = ControlChars.NewLine then MessageBox.Show("It is a newline") end if
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7367
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5654
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
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 we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.