I having a strange problem when I’m trying to produce an XML file with PHP. The problems is that, a strange question mark appears at the end of the source code. And I get the error: “Extra content at the end of the document”
I’m running this script:
<?php header("Content-Type: application/xml"); echo "<?xml version=\"1.0\"?>"; ?> <Module> <ModulePrefs title="Ngram Extractor" author="interedition team" description="Ngram Extractor" scrolling="true"/> <Content type="html"> Test </Content> </Module>
When I open this is a browser, I get the state error and the source code looks like this. Notice the strange question mark at the end.
<?xml version="1.0"?> <Module> <ModulePrefs title="Ngram Extractor" author="interedition team" description="Ngram Extractor" scrolling="true"/> <Content type="html"> Test </Content> </Module>?
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
You have a zero width space character at the end of your file – UTF-8 code E2 80 8B. It is placed right after
</Module>. Have a look at your file in hex mode.
This extra character prevents your browser from recognizing this as valid XML and – depending on the browser in use – shows up as a question mark or does not show up at all.
Remove that extra character and you will be fine.
May be you use UTF-8 with BOM encoding. Check it
I don’t really have answer, accept that my editor wasn’t showing the question mark. But one I opened the file in notepad2, lo and behold, the question mark was there. Very strange. Thanks for your help.
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂