|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28339 simplexml_load_string chokes on " "
Submitted: 2004-05-09 21:29 UTC Modified: 2004-05-09 23:58 UTC
From: cwood at austin dot rr dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.0.0RC2 OS: Mac OS X 10.2.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: cwood at austin dot rr dot com
New email:
PHP Version: OS:


 [2004-05-09 21:29 UTC] cwood at austin dot rr dot com
When trying to load a string containing an HTML-encoded 
non-breaking space (" ") with 
simplexml_load_string, I get the following warning:

Warning:  Entity: line 14: error: Entity 'nbsp' not 
defined in /Library/WebServer/Documents/simple.php on 
line 11
But other HTML-escaped characters like > and < 
make it through fine.

Reproduce code:
$xmlstr = <<<XML
<?xml version='1.0'?>
 <title>This is the title</title>
 <description>This&nbsp;is the description</description>

$xml = simplexml_load_string(utf8_encode($xmlstr)); 
foreach($xml->channel->item as $item) { 
echo "<b><a href=".$item->link.">".$item->title."</a></b><br>".$item->description."<p>";

Expected result:
<b><a href=>This is the title</
a></b><br>This is the description<p>

Actual result:
Warning:  Entity: line 7: error: Entity 'nbsp' not 
defined in /Library/WebServer/Documents/test.php on 
line 15
 Warning:   This?is the description in /Library/
WebServer/Documents/test.php on line 15
 Warning:                          ^ in /Library/
WebServer/Documents/test.php on line 15
 Warning:  Invalid argument supplied for foreach() in /
Library/WebServer/Documents/test.php on line 16


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-09 23:53 UTC]
&nbsp; is not a defined XML entity. In XML, you can only 
use &lt;, &gt;, &amp;, &quot; and &apos;. For other 
entities you must use numeric character references. See:
 [2004-05-09 23:58 UTC] cwood at austin dot rr dot com
DOH! Thanks. PHP rocks.
 [2004-05-18 08:50 UTC] becharakordahi at hotmail dot com
I am a student learning php and xml .
And I have difficulty by resolving some problems such as

when I use "simplexml_load_string()" function 
I have this error: 

Fatal error: Call to undefined function: simplexml_load_string() in c:\inetpub\wwwroot\E_Learning\PHP\tryout\tt.php on line 14
this is the code i try :
$string = <<<XML
<?xml version='1.0'?> 
<title>Forty What?</title>
  I know that's the answer -- but what's the question?

$xml = simplexml_load_string($string);


how can I resolve this problem
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jun 03 07:03:39 2023 UTC