标头特殊字符转换?
我的 php 页面标题上的字符转换存在一些问题。
我必须开发一段代码,即 WS(xml-rpc 协议),可以与用 python 编写的另一段代码进行交互。
这是 python 代码片段的输出:
Output={'metaTagKeyWords': '', 'metaTagTitle': '10% DISCOUNT FOR 3 NIGHTS','metaTagDescription': 'Questa \xc3\xa8 una prova: devo vedere che succede.\r\n\r\nProva prova.\r\n\r\nDaje.\r\n\r\nENGLISH VERSION !!!!\r\n'}
所以我必须转换一些字符:首先 \xc3\xa8 这是“è”的 unicode 转换,第二次是 "\ r\n\" 个字符。
我知道如何处理 "\r\n\" 字符,但我不知道如何转换 unicode 字符。
我已经尝试过做这样的事情:
htmlentities($data[$META_TITLE_KEY], ENT_QUOTES, 'UTF-8')
但它不起作用。
,我已经尝试在 pyhon 中转换 UTF-8 中的字符串(这样实体将是 u'\xc3' 或类似的东西,但结果非常相同。)
此外 信息:该转换必须在 php 文件头中使用,转换为“元标记描述”标记。
EDIT1:
我们认为的 UTF-8 似乎是 LATIN-1。所以,如果我改变标题中的那部分:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
它就
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1" />
可以工作。
但我必须有一个 utf-8 字符集;所以我想必须在Python应用逻辑中做一些事情(因为当我从编辑器转到数据库时我编码一些东西,而当我从数据库返回到编辑器时我解码一些东西)。 请继续关注更多信息
EDIT2:
也许我使用一些函数将数据保存到 Postrges DMB 上,将数据转换为 latin-1,然后转换为 utf-8。所以,如果我添加这条指令:
d_meta[element] = codeDbToEditor(d_meta[element]).replace('\r\n', ' ').decode('latin-1')
一切似乎都有效。
我有正确的“灵感”吗?
I have some problems with char conversion on my php's page header.
I have to develop a snippet of code that, means WS (xml-rpc protocol), can interface with another snippet of code wrote in python.
This is python snippet's output:
Output={'metaTagKeyWords': '', 'metaTagTitle': '10% DISCOUNT FOR 3 NIGHTS','metaTagDescription': 'Questa \xc3\xa8 una prova: devo vedere che succede.\r\n\r\nProva prova.\r\n\r\nDaje.\r\n\r\nENGLISH VERSION !!!!\r\n'}
So I have to convert some char: first of all \xc3\xa8 that is the unicode conversion of "è" and, in a second time, the "\r\n\" chars.
I know how to procede with "\r\n\" chars, but I don't know how to convert the unicode char.
I have had alredy tried to do something like this:
htmlentities($data[$META_TITLE_KEY], ENT_QUOTES, 'UTF-8')
But it dind't work.
Moreover, I had alredy tried to convert in pyhon the string in UTF-8 (so that entity would be u'\xc3' or something like that, but the results are pretty the same.)
An additional info: that conversion have to be used on php file header, into "meta tag description" tag.
EDIT1:
It's seems to be that, what we belive as an UTF-8, is instead a LATIN-1. So, if i change in the header that part:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
in
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1" />
it works.
But I have to have a utf-8 charset; so I suppose that have to do something in python applicative logic (because when I go from editor to DB i encode something while when I return from DB to editor I decode something).
Stay tune for more info
EDIT2:
Maybe some function that i use to save my data onto Postrges DMB, convert data in latin-1 and then in utf-8. So, if I add this instruction:
d_meta[element] = codeDbToEditor(d_meta[element]).replace('\r\n', ' ').decode('latin-1')
everything seems to works.
Have I had the right "insipration"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望有帮助
Hope It Helps