Why when add <?xml version=“1.0” encoding=“utf-8”?> to web page don´t work on hosting?

拟墨画扇 提交于 2019-11-27 08:25:44

问题


I am developing a simple webpage at hostgator.com. I have the standard headers, but when I add the following line:

<?xml version="1.0" encoding="utf-8"?> 

the page does not work. I would like why.

This is the full header:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es"> 
... rest of code ...

The server returns me a blank page


Issue solved: The PHP short tags was open.


回答1:


My best guess is that:

  • The document is being processed as PHP
  • Short Tags are turned on

… so the server is trying to process the XML declaration as PHP code. Normally I'd expect an error message, but perhaps there is a PHP setting in play that suppresses errors to the client to avoid leaking data that could be potentially useful to someone trying a security exploit.

Just remove it.

  • UTF-8 is the default
  • version 1.0 is the default
  • It is optional in the spec
  • Given a text/html content-type, an XML prolog will trigger IE6's quirks mode

The latter is undesirable. The former all mean it makes no difference.




回答2:


<?php
echo '<?xml version="1.0" encoding="utf-8"?>';
?>



来源:https://stackoverflow.com/questions/4361750/why-when-add-xml-version-1-0-encoding-utf-8-to-web-page-don%c2%b4t-work-on-ho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!