How do I remove a \ufeff character in my webpage s

2020-02-04 20:19发布

I am trying to, simply put, remove a hidden zero-width-line-break character (U+FEFF) in my script. The webpage that it has appeared on is at http://cynicode.co.uk (Please note, the index page has been tinkered with and is the only one which functions properly at the moment)

By looking at the html elements on the page, this shows up:

enter image description here

The key point being the red dot between < body > and < !--5-- >. This, when hovered over, shows that it is a \ufeff character. The problem is that, when I look through the script, there is no such character that exists.

I am using PHP and HTML to construct this page, and the items between < !--4-- > and < !--5-- > consists of the following. Firstly, on the actual index page itself:

<?php
  echo "<!--4-->";
  echo "<head><meta charset='utf-8' /><link rel='shortcut icon' type='image/ico' href='./images/CyniCode.ico'>
    <title>CyniCode :: Index</title>
    <meta name='description' content='The Cynic's paradise! Home of Cynical.' />
    <meta name='author' content='Cynical' />
    <meta name='keywords' content='Cynical;Blog;Code' />
    <link type='text/css' rel='stylesheet' href='./css/mystyle.css' />
    <link rel='shortcut icon' type='image/ico' href='./images/CyniCode.ico'>
    <link href='http://fonts.googleapis.com/css?family=Muli' rel='stylesheet' type='text/css' />
    <script type='text/javascript' src='http://static.proofiction.net/jquery/jquery-1.9.1.min.js'></script>
    <script type='text/javascript' src='http://static.proofiction.net/jquery/loginwait.js'></script>
    <script type='text/javascript' src='http://static.proofiction.net/jquery/googleAnalytics.js'></script>
    <script type='text/javascript' src='./http://static.proofiction.net/jquery/jquery.bxslider.js'></script>
    <script type='text/javascript' src='./http://static.proofiction.net/jquery/jquery.bxslider.min.js'></script>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'><!--
      google_ad_client = 'ca-pub-xxxxxxxxxxxx';
      /* BiggerNavBox */
      google_ad_slot = '3977705372';
      google_ad_width = 300;
      google_ad_height = 600;
      //-->
    </script>
    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-xxxxxxxx-1', 'cynicode.co.uk');
      ga('send', 'pageview'); 
    </script>

    </head>";
  require_once './functions/page.php';

This constitutes for the Index page. The page.php script referenced is my cheat for setting the page up quickly and cleanly. However... there is a small remaining difference between the two comments on the page. This is the remaining difference between the two comments.

<?php
  echo "<!--5-->";

Any help that anyone can offer would be much appreciated. All code pieces were direct copy and pastes from my scripts.

标签: php html utf-8
2条回答
三岁会撩人
2楼-- · 2020-02-04 20:49

Some of your .php files (probably ./functions/page.php contains Byte Order Mark. If you are using some IDE, check this file's encoding properties and with luck you will be able to remove it.

Edit If you use *nix, Elegant way to search for UTF-8 files with BOM? should help.

查看更多
放我归山
3楼-- · 2020-02-04 21:04

Here is a solution to a similar issue: Extra BOM character in HTML invalidating DOCTYPE tag

Basically the source of the issue are PHP files encoded in UTF8 with BOM, encoding them in UTF-8 without BOM solves the issue.

Notepad++ UTF-8 encoding without BOM

查看更多
登录 后发表回答