如何在网页脚本中删除\ ufeff字符?

J4N*_*ers 11 html php utf-8

我试图简单地说,在我的脚本中删除一个隐藏的零宽度换行字符(U + FEFF).它出现的网页是http://cynicode.co.uk(请注意,索引页面已被修改,是目前唯一正常运行的页面)

通过查看页面上的html元素,显示:

在此输入图像描述

关键点是< body >和之间的红点< !--5-- >.这种情况在盘旋时表明它是一个\ufeff角色.问题是,当我查看脚本时,没有这样的字符存在.

我使用PHP和HTML来构建此页面,以及之间的项目< !--4-- >< !--5-- >由以下内容组成.首先,在实际的索引页面上:

<?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';
Run Code Online (Sandbox Code Playgroud)

这构成了索引页面.引用的page.php脚本是我的作弊,可以快速,干净地设置页面.但是......页面上的两条评论之间存在一点差异.这是两条评论之间的剩余差异.

<?php
  echo "<!--5-->";
Run Code Online (Sandbox Code Playgroud)

任何人都可以提供任何帮助将非常感激.所有代码片段都是我脚本中的直接复制和粘贴.

Cth*_*lhu 22

你的一些.php文件(可能./functions/page.php包含Byte Order Mark.如果你使用的是某些IDE,请检查这个文件的编码属性,幸运的是你可以删除它.

编辑如果您使用*nix,优雅方式搜索带BOM的UTF-8文件?应该有所帮助

  • @ M477h3w1012 Yoy可以查看http://www.bryntyounce.com/filebomdetector.htm. (2认同)

sap*_*ish 12

以下是类似问题的解决方案:HTML中的额外BOM字符使DOCTYPE标记无效

基本上问题的根源是编码的PHP文件UTF8 with BOM,编码它们UTF-8 without BOM解决了这个问题.

没有BOM的Notepad ++ UTF-8编码