我真的需要编码 '&'作为“&"? [英] Do I really need to encode '&' as '&'?

查看:25
本文介绍了我真的需要编码 '&'作为“&"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我网站的 </code> 中使用带有 HTML5 和 UTF-8 的<code>&</code>"符号.谷歌在其<a href="https://en.wikipedia.org/wiki/Search_engine_results_page" rel="nofollow noreferrer">SERP</a>上显示&符号罚款,标题中的所有浏览器也是如此.</a>><p><a href="http://validator.w3.org" rel="nofollow noreferrer">http://validator.w3.org</a> 给了我这个:</p><块引用><p>&没有开始字符引用.(& 可能应该被转义为 <code>&amp;</code>.)</p></blockquote><p>我真的需要做<code>&amp;</code>吗?</p><p>我不会为了验证而对我的页面进行验证,但我很想听听人们对此的看法,以及它是否重要以及为什么.</p><div class="h2_lin"> 解决方案 </div><p>是的.正如错误所说,在 HTML 中,属性是 #PCDATA 意味着它们被解析.这意味着您可以在属性中使用字符实体.单独使用 <code>&</code> 是错误的,如果不是对于宽松的浏览器以及这是 HTML 而不是 XHTML 的事实,将会破坏解析.将它转义为 <code>&amp;</code> 一切都会好起来的.</p><p>HTML5 允许您不转义它,但前提是后面的数据看起来不像有效的字符引用.然而,与其担心哪些应该是,哪些不需要,不如逃避这个符号的所有实例.</p><p>记住这一点;如果你没有逃避 &到 &amp;,对于您创建的数据(其中代码很可能无效)来说,这已经够糟糕了,您也可能没有转义标记分隔符,这对于用户提交的数据来说是一个巨大的问题,这很可能会导致HTML 和脚本注入、cookie 窃取和其他攻击.</p><p>请转义您的代码.以后会省去很多麻烦.</p><p>I'm using an '<code>&</code>' symbol with HTML5 and UTF-8 in my site's <code><title></code>. Google shows the ampersand fine on its <a href="https://en.wikipedia.org/wiki/Search_engine_results_page" rel="nofollow noreferrer">SERPs</a>, as do all the browsers in their titles.</p> <p><a href="http://validator.w3.org" rel="nofollow noreferrer">http://validator.w3.org</a> is giving me this:</p><blockquote> <p>& did not start a character reference. (& probably should have been escaped as <code>&amp;</code>.)</p> </blockquote><p>Do I really need to do <code>&amp;</code>?</p> <p>I'm not fussed about my pages validating for the sake of validating, but I'm curious to hear people's opinions on this and if it's important and why.</p><div class="h2_lin"> 解决方案 </div><p>Yes. Just as the error said, in HTML, attributes are #PCDATA meaning they're parsed. This means you can use character entities in the attributes. Using <code>&</code> by itself is wrong and if not for lenient browsers and the fact that this is HTML not XHTML, would break the parsing. Just escape it as <code>&amp;</code> and everything would be fine.</p> <p>HTML5 allows you to leave it unescaped, but only when the data that follows does not look like a valid character reference. However, it's better just to escape all instances of this symbol than worry about which ones should be and which ones don't need to be.</p> <p>Keep this point in mind; if you're not escaping & to &amp;, it's bad enough for data that you create (where the code could very well be invalid), you might also not be escaping tag delimiters, which is a huge problem for user-submitted data, which could very well lead to HTML and script injection, cookie stealing and other exploits.</p> <p>Please just escape your code. It will save you a lot of trouble in the future.</p> <p>这篇关于我真的需要编码 '&'作为“&amp;amp;"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!</p> </div> <div class="arc-body-main-more"> <span onclick="unlockarc('2657083');">查看全文</span> </div> </div> <div> </div> <div class="wwads-cn wwads-horizontal" data-id="166" style="max-width:100%;border: 4px solid #666;"></div> </div> </article> <div id="arc-ad-2" class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="widget bgwhite radius-1 mb-1 shadow widget-rel"> <h5>相关文章</h5> <ul> <li> <a target="_blank" title="我真的需要编码'&amp;'作为'&amp; amp;'?" href="/506932.html"> 我真的需要编码'&amp;'作为'&amp; amp;'?; </a> </li> <li> <a target="_blank" title="Antixss GetSafeHtmlFragment编码&amp;作为&amp; amp;" href="/1118796.html"> Antixss GetSafeHtmlFragment编码&amp;作为&amp; amp;; </a> </li> <li> <a target="_blank" title="mysqli - 我真的需要做 $result->close();&amp;$mysqli->close();?" href="/2715719.html"> mysqli - 我真的需要做 $result->close();&amp;$mysqli->close();?; </a> </li> <li> <a target="_blank" title="使用&amp;&amp;&amp;&amp;&amp;'s的短路作为if语句?" href="/1004413.html"> 使用&amp;&amp;&amp;&amp;&amp;'s的短路作为if语句?; </a> </li> <li> <a target="_blank" title="是否&amp;需要&amp; amp;在元描述?" href="/557438.html"> 是否&amp;需要&amp; amp;在元描述?; </a> </li> <li> <a target="_blank" title="URL编码将“&amp;”(&符号)视为“&amp; amp;”HTML实体" href="/1005139.html"> URL编码将“&amp;”(&符号)视为“&amp; amp;”HTML实体; </a> </li> <li> <a target="_blank" title="编码问题,覆盖&amp; amp;到&amp;对于html使用php" href="/507542.html"> 编码问题,覆盖&amp; amp;到&amp;对于html使用php; </a> </li> <li> <a target="_blank" title="'AND' 与 '&amp;&amp;'作为运营商" href="/2870128.html"> 'AND' 与 '&amp;&amp;'作为运营商; </a> </li> <li> <a target="_blank" title="'AND'vs'&amp;&amp;'作为运算符" href="/528909.html"> 'AND'vs'&amp;&amp;'作为运算符; </a> </li> <li> <a target="_blank" title="mysqli-我真的需要做$ result-&gt; close();吗? &amp; $ mysqli-&gt; close();?" href="/1661136.html"> mysqli-我真的需要做$ result-&gt; close();吗? &amp; $ mysqli-&gt; close();?; </a> </li> <li> <a target="_blank" title="正确的字符编码,以显示“&amp; acirc;&amp;#128;&amp;#157;”?" href="/507328.html"> 正确的字符编码,以显示“&amp; acirc;&amp;#128;&amp;#157;”?; </a> </li> <li> <a target="_blank" title="不能使用&amp; amp;作为属性值" href="/1053152.html"> 不能使用&amp; amp;作为属性值; </a> </li> <li> <a target="_blank" title="我真的需要帮助" href="/1282720.html"> 我真的需要帮助; </a> </li> <li> <a target="_blank" title="html编码&amp;解码问题" href="/1244448.html"> html编码&amp;解码问题; </a> </li> <li> <a target="_blank" title="XHTML和&amp; (“&"号编码)" href="/1871175.html"> XHTML和&amp; (“&"号编码); </a> </li> <li> <a target="_blank" title="霍夫曼编码-标头&amp; amp;紧急行动" href="/1903202.html"> 霍夫曼编码-标头&amp; amp;紧急行动; </a> </li> <li> <a target="_blank" title="我如何使用&amp;&amp;&amp;与 - &gt;也许是" href="/849690.html"> 我如何使用&amp;&amp;&amp;与 - &gt;也许是; </a> </li> <li> <a target="_blank" title="我为什么要使用&amp; amp;而不是&amp ;?" href="/2122179.html"> 我为什么要使用&amp; amp;而不是&amp ;?; </a> </li> <li> <a target="_blank" title="jQuery html()和&amp; amp; amp; amp; amp; amp; amp;" href="/873018.html"> jQuery html()和&amp; amp; amp; amp; amp; amp; amp;; </a> </li> <li> <a target="_blank" title="我应该使用“&amp;&amp;”或“和”。" href="/475936.html"> 我应该使用“&amp;&amp;”或“和”。; </a> </li> <li> <a target="_blank" title="用javascript编码url而不编码&amp;" href="/1871274.html"> 用javascript编码url而不编码&amp;; </a> </li> <li> <a target="_blank" title="最佳编码标准&amp; .NET&amp;的代码评论SQL" href="/1204484.html"> 最佳编码标准&amp; .NET&amp;的代码评论SQL; </a> </li> <li> <a target="_blank" title="html编码输出&amp;&amp;错误的字符串错误" href="/508130.html"> html编码输出&amp;&amp;错误的字符串错误; </a> </li> <li> <a target="_blank" title="Laravel 4.2 链接到操作链接 &amp;amp;作为 %27" href="/2477668.html"> Laravel 4.2 链接到操作链接 &amp;amp;作为 %27; </a> </li> <li> <a target="_blank" title="我真的需要malloc吗?" href="/1592892.html"> 我真的需要malloc吗?; </a> </li> </ul> </div> <div class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="side"> <div class="widget widget-side bgwhite mb-1 shadow"> <h5>前端开发最新文章</h5> <ul> <li> <a target="_blank" title="为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?" href="/1996151.html"> 为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?; </a> </li> <li> <a target="_blank" title="错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接" href="/749568.html"> 错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接; </a> </li> <li> <a target="_blank" title="如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?" href="/1009885.html"> 如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?; </a> </li> <li> <a target="_blank" title="如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?" href="/884909.html"> 如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?; </a> </li> <li> <a target="_blank" title="警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件" href="/818517.html"> 警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件; </a> </li> <li> <a target="_blank" title="如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?" href="/343346.html"> 如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?; </a> </li> <li> <a target="_blank" title="此请求已被阻止;内容必须通过HTTPS提供" href="/886417.html"> 此请求已被阻止;内容必须通过HTTPS提供; </a> </li> <li> <a target="_blank" title="资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关)" href="/562873.html"> 资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关); </a> </li> <li> <a target="_blank" title="通过HTTPS加载页面但请求不安全的XMLHttpRequest端点" href="/885901.html"> 通过HTTPS加载页面但请求不安全的XMLHttpRequest端点; </a> </li> <li> <a target="_blank" title="拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。" href="/47347.html"> 拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。; </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门教程 </h5> <ul> <li> <a target="_blank" title="Java教程" href="/OnLineTutorial/java/index.html"> Java教程 </a> </li> <li> <a target="_blank" title="Apache ANT 教程" href="/OnLineTutorial/ant/index.html"> Apache ANT 教程 </a> </li> <li> <a target="_blank" title="Kali Linux教程" href="/OnLineTutorial/kali_linux/index.html"> Kali Linux教程 </a> </li> <li> <a target="_blank" title="JavaScript教程" href="/OnLineTutorial/javascript/index.html"> JavaScript教程 </a> </li> <li> <a target="_blank" title="JavaFx教程" href="/OnLineTutorial/javafx/index.html"> JavaFx教程 </a> </li> <li> <a target="_blank" title="MFC 教程" href="/OnLineTutorial/mfc/index.html"> MFC 教程 </a> </li> <li> <a target="_blank" title="Apache HTTP客户端教程" href="/OnLineTutorial/apache_httpclient/index.html"> Apache HTTP客户端教程 </a> </li> <li> <a target="_blank" title="Microsoft Visio 教程" href="/OnLineTutorial/microsoft_visio/index.html"> Microsoft Visio 教程 </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门工具 </h5> <ul> <li> <a target="_blank" title="Java 在线工具" href="/Onlinetools/details/4"> Java 在线工具 </a> </li> <li> <a target="_blank" title="C(GCC) 在线工具" href="/Onlinetools/details/6"> C(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="PHP 在线工具" href="/Onlinetools/details/8"> PHP 在线工具 </a> </li> <li> <a target="_blank" title="C# 在线工具" href="/Onlinetools/details/1"> C# 在线工具 </a> </li> <li> <a target="_blank" title="Python 在线工具" href="/Onlinetools/details/5"> Python 在线工具 </a> </li> <li> <a target="_blank" title="MySQL 在线工具" href="/Onlinetools/Dbdetails/33"> MySQL 在线工具 </a> </li> <li> <a target="_blank" title="VB.NET 在线工具" href="/Onlinetools/details/2"> VB.NET 在线工具 </a> </li> <li> <a target="_blank" title="Lua 在线工具" href="/Onlinetools/details/14"> Lua 在线工具 </a> </li> <li> <a target="_blank" title="Oracle 在线工具" href="/Onlinetools/Dbdetails/35"> Oracle 在线工具 </a> </li> <li> <a target="_blank" title="C++(GCC) 在线工具" href="/Onlinetools/details/7"> C++(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="Go 在线工具" href="/Onlinetools/details/20"> Go 在线工具 </a> </li> <li> <a target="_blank" title="Fortran 在线工具" href="/Onlinetools/details/45"> Fortran 在线工具 </a> </li> </ul> </div> </div> </div> <script type="text/javascript">var eskeys = '我,真的,需要,编码,作为,amp,amp'; var cat = 'cc';';//qianduan</script> </div> <div id="pop" onclick="pophide();"> <div id="pop_body" onclick="event.stopPropagation();"> <h6 class="flex flex101"> 登录 <span onclick="pophide();">关闭</span> </h6> <div class="pd-1"> <div class="wxtip center"> <span>扫码关注<em>1秒</em>登录</span> </div> <div class="center"> <img id="qr" src="https://huajiakeji.com/Content/Images/qrydx.jpg" alt="" style="width:150px;height:150px;" /> </div> <div style="margin-top:10px;display:flex;justify-content: center;"> <input type="text" placeholder="输入验证码" id="txtcode" autocomplete="off" /> <input id="btngo" type="button" onclick="chk()" value="GO" /> </div> <div class="center" style="margin: 4px; font-size: .8rem; color: #f60;"> 发送“验证码”获取 <em style="padding: 0 .5rem;">|</em> <span style="color: #01a05c;">15天全站免登陆</span> </div> <div id="chkinfo" class="tip"></div> </div> </div> </div> <script type="text/javascript" src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/highlight.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/base.js?v=0.22"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/tui.js?v=0.11"></script> <footer class="footer"> <div class="container"> <div class="flink mb-1"> 友情链接: <a href="https://www.it1352.com/" target="_blank">IT屋</a> <a href="https://huajiakeji.com/" target="_blank">Chrome插件</a> <a href="https://www.cnplugins.com/" target="_blank">谷歌浏览器插件</a> </div> <section class="copyright-section"> <a href="https://www.it1352.com" title="IT屋-程序员软件开发技术分享社区">IT屋</a> ©2016-2022 <a href="http://www.beian.miit.gov.cn/" target="_blank">琼ICP备2021000895号-1</a> <a href="/sitemap.html" target="_blank" title="站点地图">站点地图</a> <a href="/Home/Tags" target="_blank" title="站点标签">站点标签</a> <a target="_blank" alt="sitemap" href="/sitemap.xml">SiteMap</a> <a href="/1155981.html" title="IT屋-免责申明"><免责申明></a> 本站内容来源互联网,如果侵犯您的权益请联系我们删除. </section> <!--统计代码--> <script type="text/javascript"> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?0c3a090f7b3c4ad458ac1296cb5cc779"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script type="text/javascript"> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </div> </footer> </body> </html>