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

How to Remove Carriage return and line feeds.

P: 8
Hi.

I have form that has a text box. I want insert unformatted text into the database.
Even if the user gives an carriage return or New line feed in the database it should be stored as on single line without any formatting.

I just want to remove
New Line Feed(\n)
Carriage Return(\r)
spaces at the begin and end of the string.

Eg:
If i have
text1(enter key pressed)
text2(enter key pressed)
text3(enter key pressed)
Blank space
Blank space

I want this to be stored in the DB as:
text1 text2 text3

Could someone help me with this?

Thanks
Apr 7 '08 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
For removing characters you can use the str_replace() command.

We can help you when you start writing your own code. Then come back here when you run into problems or have questions. We do not supply ready made code.

Ronald
Apr 7 '08 #2

P: 8
I already have the code ,Everything works fine but i want to store the data from a textarea without any formatting into the database.

Currrently it stores data with formatting like (\n)(\r)
i want to strip them off. and use one single line with spaces between words.

i used str_replace() but that does not seem to work.

Can someone helpme with this.

Thanks
Apr 7 '08 #3

100+
P: 105
Try str_replace() with ascii codes
Apr 7 '08 #4

ronverdonk
Expert 2.5K+
P: 4,258
Show your str_replace command here. I wonder if you defined the \n and \r within single quotes. When you did: that does not work. You have to include them within double quotes.

Show your str_replace() command anyway (within code tags)

Ronald
Apr 7 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.