Additional Content at the End of a PHP and XML Document

I have a strange problem when I try to create an XML file with PHP. The problem is that a strange question mark appears at the end of the source code. And I get an error: "Extra content at the end of the document"

I run 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 browser, I get a status error, and the source code looks like this. Note 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>? 

Please, help.

+4
source share
3 answers

You have a space character at zero width at the end of your file - UTF-8 E2 80 8B code. It is placed immediately after the </Module> . Look at your file in hex mode. This extra character prevents your browser from recognizing it as valid XML and - depending on the browser you use - is displayed as a question mark or not displayed at all.

Remove this extra character and everything will be fine.

+7
source

Maybe you are using UTF-8 with BOM encoding. Check it out

0
source

I have no answer, agree that my editor did not show a question mark. But I opened the file in notepad2, and so, the question mark was there. Very strange. Thank you for your help.

0
source

Source: https://habr.com/ru/post/1390817/


All Articles