|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55279 SimpleXml removes line breaks
Submitted: 2011-07-25 06:17 UTC Modified: 2012-09-20 06:51 UTC
Avg. Score:3.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mathieu at webberig dot be Assigned: rrichards (profile)
Status: Not a bug Package: SimpleXML related
PHP Version: 5.3.6 OS: 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mathieu at webberig dot be
New email:
PHP Version: OS:


 [2011-07-25 06:17 UTC] mathieu at webberig dot be
SimpleXML seems to ignore/remove line breaks (\n) in the attributes. Line breaks 
inside an attribute are valid XML, but they're lost when you use SimpleXML to read 
the XML data.

I encountered this problem when reading XML data provided by the Google Webmaster 
Tools API

Test script:
<?xml version="1.0"?>
<feed><entry description="this is the first line
here's a second line
and another!" /></feed>

$xml = simplexml_load_string($xmldata);
foreach ($xml->entry as $entry)
$attributes = $entry->attributes();

Expected result:
Keep the line breaks from the attribute values after reading the string.
$attributes['description'] == "this is the first line
here's a second line
and another!";

Actual result:
The string no longer contains line breaks:
$attributes['description'] == "this is the first line here's a second line and 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-25 06:27 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: rrichards
 [2011-07-25 06:27 UTC]
As says than new lines are valid in 
attribute values, it seems that almost no parser returns them.

This is certainly a problem in libxml itself as simplexml does not transform the 
values returned by libxml.

Assigne to Rob so he can check with the libxml devs, whether we like to change 
that or not :)
 [2012-09-20 06:51 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Attribute values are normalized:
 [2012-09-20 06:51 UTC]
-Status: Assigned +Status: Not a bug
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 12 23:01:35 2024 UTC