php vs htm, weird gaps

2019-08-21 09:13发布

问题:

the normal one:

http://labvc.x10hosting.com/AT/site/home.htm

VS

the odd one:

http://labvc.x10hosting.com/AT/site/home.php

when i look at the code side by side, its almost identical, the only thing that would make them give that weird gap should be the CSS but they're using the same sheet.

ideas?


EDIT: I checked and made minute changes to the code, look again at the source.
Both are EXACTLY the same. wtf is with this gap.


EDIT: there's a pixel wide character just before the xml deceleration, how do i stop it form occurring?

回答1:

Your PHP output has a double byte-order-mark at the head.

Inspecting your code with Firebug, I see this as the first line

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

Now, all those funky characters there are just ISO-8859-1 decodings of the UTF-8 BOM (0xEF 0xBB 0xBF).

These are possibly added by your IDE/editor into the head of the PHP files themselves. Check your preferences and see what encoding is being used. If it's something like "UTF-8 + BOM" then switch it to just "UTF-8" and that should fix it.



回答2:

There's a on the php one at the top of the page explaining the gap IMHO



回答3:

The php page generates a "." before the doctype which explain the extra space

the html page

<!DOCTYPE html

    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

the php page

.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

delete any code above the doctype in the php page



回答4:

If you're including any files at the top of the PHP file it could be that you actually have whitespace or a period AFTER the ending ?> in the included file

header.php
<?php
  phpstuff...
?> <whitespace or period here>

home.php
<?php
  include "header.php";
?>

This can be solved by never using ?> in pure PHP files. It's ok to leave it open like this:

<?php
  phpstuff...


回答5:

You have an extra bit of white space at the top of the PHP file's source code (before the xml declaration).



标签: php css xhtml