[Solved]XML document saved with bad formatting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

abeall wrote:So if PHP is getting \n, why is it converting them to 
, if it doesn't help anyway?
A friend of mine usually answers these kind of questions with "because it can" ;)
All I can tell you is php calls the function xmlNewDocNode of libxml2 to create a new text node. Maybe you can contact someone more involved with http://xmlsoft.org/index.html to answer your question.
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post by abeall »

Fair enough. And great idea, I'll head over to xmlsoft and see if they can help me solve my problem. I'll report back if I find anything.

Thanks, all!
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post by abeall »

Solution:

Code: Select all

foreach ($_POST as $key => $val)
	$_POST[$key] = str_replace("\r",'',$_POST[$key]);
Apparently, the parser converts \r to $#xD; but leaves \n alone. Since I was posting from a Windows machine, the data has \r\n at the end of each line, and the parser encoded \r but left \n alone. So stripping out the useless \r fixed things.
Post Reply