我从php脚本中检索了以下文本(其中一些是汉字)作为选择选项,但无法将它们转换为可读字符(无论是通过php还是javascript),请指教。
\\xe8\\xac\\x9b\\xe5\\x91\\xa2D\\xe3\\x80\\x82
最佳答案
input = '\xe8\xac\x9b\xe5\x91\xa2D\xe3\x80\x82'
console.log(decodeURIComponent(escape(input)))
这给了你准确的
講呢D。
更新
如果你的字符串确实包含\x
字符,那么我们可以先将它们转换为%
s:
input = '\\xe8\\xac\\x9b\\xe5\\x91\\xa2D\\xe3\\x80\\x82'
decodeURIComponent(input.replace(/\\x/g, '%'))
关于javascript - 通过javascript转换unicode字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20701667/