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 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动