Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
740 views
in Technique[技术] by (71.8m points)

wordpress - HTML validation error: Non-space characters found before DOCTYPE

I have a blog(wordpress based). And try to validate by w3c validator one of my page. The first error is:

Line 1, Column 1: Non-space characters found without seeing a doctype first. Expected <!DOCTYPE html>.
<!DOCTYPE html><!-- HTML 5 -->

Also, DebugBar (http://www.my-debugbar.com/wiki/IETester/HomePage) agree and show two invisible chars before <! when I open the same page from "HTML Check" tab inside this tool. BUT!!

  1. This line of HTML-code come from file header.php in my wordpress theme.
  2. I download this file from my hoster to my local HDD.
  3. The first line of header.php is <!DOCTYPE html><!-- HTML 5 -->
  4. When I open header.php in RJ TextEd (just advanced text editor) it say: current encoding for header.php is UFT-8 without(!) BOM.
  5. When I open header.php in HEX-viewer I see, that byte 0 and 1 is 3c,21 - so it is exactly <!.

So, all things considered, why & where I get these "odd symbols" from?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the root of problem. The general rule is:

If any(absolutely any!) file that take part in construction of the code of final HTML-page(the one to be sended to client) has encoding with BOM - final HTML-page WILL BE UTF-8-BOM. That is: you whole site should NOT contain even 1 file with BOM.

In my case I have total 1.3K files that make up my site. Only 4 files was BOMed:

  • wp-config.php (in root of site)
  • jquery.query.js (in include folder)
  • cyr-to-lat.php (in plug-in folder)
  • footer.php (in theme root folder)

And I was forced to re-save every and all of these 4 files as "UFT-8 without BOM" to get rid of "Non-space characters" validation error. When I did this (re-save files) - error is gone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...