[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

processing line breaks: html text area to database to xml: ^M

Posted on 2006-04-11
4
Medium Priority
?
335 Views
Last Modified: 2008-03-06
Hi,

I have an adhoc cms system, where the user types in content into a text area. Then I save it to a mysql db. Then I have a script which pulls from the DB and inserts into an xml file using php DOM XML functions (php 4). The problem is, in the xml file the line breaks are coming out like so:

^M

I should convert these when I pull it from the database, but before I write it to the xml. THe question is, what character code is this and what character code do I replace it with?

Thanks
0
Comment
Question by:MaritimeSource
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 900 total points
ID: 16431293
When you hit enter a Carriage Return/Line Feed pair are inserted into most programs.

This is ASCII chars 13 and 10 respectively.  Depends upon where you will be displaying the string and if you want to keep the line breaks. If it will be displayed as HTML then you could change it to <BR>

If you don't want to keep line break, strip them out.
0
 

Author Comment

by:MaritimeSource
ID: 16431333
I want to keep the line break, but I don't want it to show up as ^M in the xml output file. I think this is happening because the web app is used on a windows machine, but the xml is created on a linux server. So I think I should strip the ASCII char 10 and leave the 13 in there? I want to kee the line break, but don't want to convert it to <br> for other reasons. I think the 10 is the one windows introduces.

Why would microsoft ever do such a thing anyway??? DOH
0
 
LVL 12

Assisted Solution

by:jessegivy
jessegivy earned 600 total points
ID: 16431586
yea, microsoft is evil, congrats on using a linux server ;)

>>I think the 10 is the one windows introduces.  
As mentioned above windows inserts "\n\r" every time you hit the enter key.  Also the textarea should have wrap=virtual or wrap=soft so that the word wrap line feeds aren't added to the db.  I believe the default is soft but if wrap=hard is specified then those word wraped line terminations will appear in the db.

...anyway, if you wanna keep them, first you'll need to figure how to insert on linux, i.e. what character linux uses, I believe it's just a single '\n'

...then, one idea would be to replace the "\n\r" with an identifiable string which will be replaced again on the client.  A string I use a lot for this kinda thing is"-----"

It's a huge pain in the butt!  It's not entirely Microsofts fault either.  I mean damn, can we just use ONE character set, is it that hard?!?  I've experimented with unicode and honestly, don't know if I'm dumb, but that didn't really work either, you've still gotta translate from whatever damn character set the data originated, huge can o worms.

...I wish you luck!

Jesse
0
 
LVL 25

Expert Comment

by:SStory
ID: 16435635
You are correct.  Unix only uses one of the chars, but Microsoft uses two chars.
Well Carriage return is to go back to the start (left side) horizontally and linefeed to go to the next line.  I guess this carried over from something in computer history.

I would try getting rid of the 10 and see if it works. I assume you are displaying this on a Unix/linux machine and that is why it is a problem.

The <BR> in HTML is platform independent, but I understand why you don't want to fool with it.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question