dsiftnc99059 2015-02-18 04:31
浏览 27
已采纳

在PHP实现后,标题被取代(UTF-8 BOM)

My company had a decent website before I joined them, outsourced and untouched for years since. After joining I've been slowly improving it in my free-time.

This week I rewrote the header/left-column/footer which are the same on all pages so that I could include them using PHP and avoid fixing them one-by-one when I want to change something (among other benefits).

I'm not well-versed in messing with the .htaccess nor PHP but really all that I have changed is:

  1. Allowing PHP to work with .html files by adding to .htaccess:

AddType application/x-httpd-php5 .html .htm

  1. I changed:

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

To:

<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ";?>

To avoid the <?xml tag from throwing PHP short tag errors

  1. copy and pasted the three common elements, header, left-column, and footer into separate HTML files and and included them using:

<?php include '_header.html';?>

  1. changed the upper left text a little, but that shouldn't affect anything.

Looking at the source code after loading both pages (PHP include and plain html) they look identical. I haven't changed any of the CSS and so they are using the same code.

Yet for some reason switching to the PHP include version adds an empty line at the top of the page.

Here is the current (plain XHTML) version: http://www.akidc.co.jp/index.html The new file for reference is: ((removed outdated link)) (I can't change the .htaccess until I upload all the new pages at once or the <?xml tag will error them all so it's up'd as a .php)

The header file I'm including is at _header.html

Please help me solve the gap ^_^

  • 写回答

1条回答 默认 最新

  • doukun5339 2015-02-18 04:39
    关注

    Run a diff on the source, you'll immediately notice what's going here.

    In the PHP version, you have a U+FEFF just before the <div id="header" ...>. This is interpreted as content by the browser, so it attempts to display this content.

    In order to solve the issue, make sure all your source code is stored in UTF-8 format.

    By the way, here's the diff:

    enter image description here

    See that <feff>?

    And now, look at the elements of your page. This is what you had before:

    enter image description here

    and this is what you get in PHP version:

    enter image description here

    Notice the additional " " block I highlighted?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器