[英]Utf8 encoding not working correctly in node js
I have installed utf8 module in my node js sever: 我已经在节点js服务器中安装了utf8模块:
here is my code 这是我的代码
var utf8 = require('utf8');
console.log(utf8.encode('It’s a way of looking.'));
//output:- It’s a way of looking.
It's not producing same output as php does: 它不会产生与php相同的输出:
echo utf8_encode('It’s a way of looking.');
//output :- It’s a way of looking.
Is it a bug in utf8 module in node js or I'm doing something wrong? 是节点js的utf8模块中的错误,还是我做错了什么?
’
is an HTML entity. 是HTML实体。 If you're not viewing the output as HTML, then you will see it as ’
如果您不以HTML格式查看输出,则它将以’
查看’
. 。 If you want to output a particular character code in JavaScript, use a JavaScript escape sequence: 如果要在JavaScript中输出特定的字符代码,请使用JavaScript转义序列:
console.log(utf8.encode('It\u2019s a way of looking.'));
it's not utf8 encoding issue it's an html entity issue 这不是utf8编码问题,而是html实体问题
here is the code:- 这是代码:-
var Entities = require('html-entities').XmlEntities;
entities = new Entities();
console.log(entities.decode('It’s a way of looking.'));
//output:- It’s a way of looking.
thankyou @JLRishe for pointing it out. 谢谢@JLRishe指出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.