php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44741 dom mangles returns (\r)
Submitted: 2008-04-16 10:41 UTC Modified: 2008-04-16 12:16 UTC
From: php at benjaminschulz dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3CVS-2008-04-16 (CVS) OS: linux, osx, windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at benjaminschulz dot com
New email:
PHP Version: OS:

 

 [2008-04-16 10:41 UTC] php at benjaminschulz dot com
Description:
------------
If you load a xml document that contains \r they are silently replaced by \n, even in CDATAs.
No matter to what ignoreWhiteSpace is set.

Reproduce code:
---------------
<?php
$doc = new DomDocument;
$xml = "<?xml version=\"1.0\"?><foo>\r \r\n <![CDATA[\r]]></foo>";
$doc->loadXml($xml);
var_dump(substr_count($doc->saveXml(), "\r"));
var_dump(substr_count($doc->saveXml(), "\n"));

Expected result:
----------------
int(3) int(1) 

This is the output of:
var_dump(substr_count($xml, "\r"));
var_dump(substr_count($xml, "\n"));

Actual result:
--------------
int(0) int(5) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-16 12:01 UTC] php at benjaminschulz dot com
this is reproducable on linux, osx and windows
 [2008-04-16 12:16 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In XML, no matter what parser you use, carriage returns are removed or 
replaced with a line feed in documents before processing them. You must 
use character entities to preserve a carriage return.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 11:01:32 2025 UTC