xml entity problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Can somebody explain why the following file
has the wrong output:

<?xml version="1.0" encoding="iso-8859-1"?>
    <elem>&#8216;bla bla bla&#8217;</elem>

Expected: ‘bla bla bla’
output: ?bla bla bla?

It's not caused by the browser, but
by the xml parser.


test script:


$file = "test.xml";

function startElement($parser, $name, $attrs) {
      global $tagname;
      $tagname = $name;

function endElement($parser, $name) {

function characterData(&$parser, $data) {
    global $testdata, $tagname;
    if(trim($data) != "") {
       switch($tagname) {
          case 'ELEM' :
                $testdata .= $data;

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, 'characterData');
if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");

while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
        die(sprintf("XML error: %s at line %d",

print "output : " .$testdata;


Re: xml entity problem

Jos van Uden wrote:

Quoted text here. Click to load it
_I know_ this sounds silly. But try
<?php echo '<'.'?xml version="1.0" encoding="iso-8859-1"?'.'>'; ?>

(that's one thing that feedvalidator drove me to do... ^^; Still having
problems, though, so if there is a specialist of RSS feed here, I'll be
happy to have help ;-) )

"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)

Site Timeline