为什么我的特殊字符“>>”被替换为带问号的菱形?

Why are my special characters '>>' being replaced with diamonds with question marks?

这是我打印特殊字符“>”和“>>”的两行代码。但是,它们在网页上显示为带问号的菱形。

paginationHtml = paginationHtml+\"<a href='javascript:void(0)' onclick='getCommentList(\"+next_page+\")'>Next› </a>&nbsp\";
paginationHtml = paginationHtml+\"<a href='javascript:void(0)' onclick='getCommentList(\"+page_count+\")'>Last» </a>&nbsp\";

确保您的 html 文件以您在 head 部分声明的相同格式保存。例如,如果您的文件是 utf-8 编码的,请将其放入您的 html:

<head>
    <meta charset="UTF-8">
</head>

如果你使用ansi编码,那么

<head>
    <meta charset="ISO-8859-8">
</head>

...等,但应该对应。如果您可以选择文件编码,请选择 utf-8.

要显示 » 等特殊字符,最简单的解决方案是将所有文档保存并显示在 UTF-8.

3 步:

1. 在您的根 .htaccess 文件中,指定

AddDefaultCharset utf-8
AddCharset utf-8 .html .css .js

2. 在您的 .html 文档的顶部,就在 <head> 下方,添加

<meta charset="utf-8">

3.重要的是,确保您使用UTF-8编码保存文本编辑器中的任何文档。

问题是我需要更改文件的编码。在 PHPStorm 中,转到 'File',然后转到 'File Encoding'。对我来说,我需要选择 'UTF-8' 编码。我转换了代码,现在“>>”字符在网站上显示正常!