如何从网页中删除外来字符

How to remove foreign characters from Web Page?

本文关键字:字符 删除 网页      更新时间:2023-09-26

我在书籍文件夹中有html文件。尝试在另一个 html 页面中使用 jQuery load 方法加载 html 文件,但它显示外来字符,例如 .

法典:

PageContentURL = "books/" + bookTitle + "/book_" + bookTitle;
$("#container").load(PageContentURL);

工作网址 :http://ashapanchal.com/TheBibleScholarHTML/chaptercontent.html?bid=2&btitle=Eastons%20Bible%20Dictionary&cid=4&ctitle=D&spi=186&epi=220&tpi=186

为什么会这样?如何删除外语字符?我已经设置了字符集并尝试了许多在线可用的解决方案。

您需要在Apache服务器上配置响应标头。

您现在拥有的只是.html文件的'Content-Type: text/html'标头。因此,您需要创建.htaccess文件(如果尚不存在(并添加以下行:

<FilesMatch "'.html$">
    Header unset Content-Type
    Header append Content-Type "text/html; charset=utf-8"
</FilesMatch>

你能:)试试这段代码吗?

str.replace(/[^'w's]/gi, '');

如果你想试试

<input type='button' value='click' id="click"/>
<input type='text' value='' id="testtt"/>

$(function(){
    $('#click').click(function(){
     var str=   $('#testtt').val();
        var newvalue =   str.replace(/[^'w's]/gi, '');
          alert(newvalue);
        });
});​

从章节内容中删除以下行.html

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

问题是主页是使用 utf-8 编码的,而您包含的页面是 iso-8859-1。因为主页是utf-8,所以它也将包含的页面解释为utf-8。