html实体不转换特殊字符 [英] html entities not converting special characters

查看:778
本文介绍了html实体不转换特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的htmlentities是转换characteres与口音,但它不转换这种类型的引号。相反,浏览器显示一个带有问号的奇怪的符号

I'm using htmlentities which is converting characteres with accents, but it is not converting this type of quotes ". Instead the browser shows a weird symbol with a question mark �

如何转换这些显示为符号的字符?
例如

How can I convert these kind of characteres that display as symbols? e.g. The book called �Hello Colors� is on the table.

我试过这个命令,但它不工作:

I've tried this commands but it's not working:

htmlentities($message);
htmlentities($message, ENT_QUOTES, 'UTF-8');
htmlentities($message, ENT_NOQUOTES, 'UTF-8');
htmlentities($message, ENT_COMPAT, 'UTF-8');

谢谢。

很奇怪,如果我做以下

echo $message; die(); 

显示一个用于调试报价的白页!
那么发生了什么?为什么在网站页面上无法正确显示? :S

to show a white page for debugging the quotes are displayed! So what is happening? Why it's not displaying correctly in the website page? :S

推荐答案

看起来您的浏览器中错过了字符集规范,

Looks like you have missed charset specification in your browser ,

请尝试在您的网页标头部分中添加< meta charset =UTF-8> 。我以前有一个这样的问题,以UTF -8显示多语言文本,我也是这样解决这个问题。

try adding <meta charset="UTF-8"> this in your webpage head section . I previously had an issue like this to display multilingual text in UTF -8 I did the same to solve this issue .

希望这有助于

BTW

HTML 5
< meta charset =UTF-8> 工作

HTML 4

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

如果是XML,您必须指定

and in case of XML you have to specify

<?xml version="1.0" encoding="UTF-8"?>

这里是您可以获取所有信息的地方

Here is the place where you can get all information

在HTML中声明字符编码

有几种方法来设置内容字符集,即使你可以设置你的服务器也始终渲染utf-8你可以在这里阅读更多信息在服务器设置部分

There are several ways to setup the content charset , even you can setup your server also to render always utf-8 you can read here for more info in the server setup section

编辑: -

Joomla

您通过在网页中插入
字符集ISO-8859进行测试,它的工作原理清楚地证明,您正在获取ISO的内容不在UTF-8

you tested by putting charset ISO-8859 in the webpage and it works this clearly proves that you are getting content in ISO not in UTF-8

probabily你的mysql数据库不是在UTF-8我想,这就是为什么它发送ISO文本到前面,你可以更改数据库为UTF- 8 general-ci或ISO latin1这是可行的,我建议你改变数据库到utf-8-general-ci,因为你已经有html页面的头设置为utf-8,这将解决你的问题。

probabily your mysql Database is not in UTF-8 I think and that is why it is sending ISO text to front , you can change the DB to UTF-8 general-ci or ISO latin1 which ever is feasible and that works I suggest you to change DB to utf-8-general-ci since you already have html pages with header set to utf-8 and that will solve your problem .

此外,如果你不能改变数据库,那么你已经知道它的ISO字符集,所以将所有的Joomla模板头更改为ISO字符集。

Also if you cant change the DB then you already know that its in ISO charset so change all your Joomla template header to ISO charset .

看起来像这个

< meta http-equiv =输入content =text / html; charset = iso-8859-1>

in php

header('Content-Type: text/html; charset=iso-8859-1'); 

这篇关于html实体不转换特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆