法语撇号字符在mysql数据库? [英] French apostrophe char in mysql database?
问题描述
我有一个mysql表,列中的一些行包含'
字符。我必须回显表内容为xml。我使用这个 utf8_encode($ row ['data'])
,数据被响应为Â'
。我使用iconv并且尝试做一个 str_replace(''','somechar',$ row ['data'])
但它现在工作。 >
看起来你需要做的就是 echo $ row ['data'];
,数据是在Windows-1252和您的页面的标题是在Windows-1252以及。不需要转换
到UTF-8。
如果你没有意识到你的数据是在windows-1252,所以设置了 encoding =UTF-8
,您可以将其设置为 encoding =Windows-1252
。
如果要使用UTF-8,应首先将连接设置为UTF-8:
mysql_set_charset(utf8);
//或$ mysqli-> set_charset(utf8);
在进行任何查询之前。
之后,您需要修复您的http标头:
<?php
header(Content-type:application / xml; charset = utf-8);
当然,不能调用 utf8_decode
。除非您真的知道您在做什么,否则不要调用 utf8_decode
或 utf8_encode
。对于初学者来说,这些功能适用于ISO-8859-1-> UTF-8(反之亦然)转换(真正的ISO-8859-1,而不是浏览器ISO-8859-1,实际上只是Windows-1252)并不是一些魔法的unicode魔杖。
如果你想采取utf-8路由还有很多其他事情,但这两个将解决你的直接问题。 / p>
i have a mysql table and some rows in a column contains ’
character. I have to echo the table content as xml. I am using this utf8_encode($row['data'])
and the data is being responded as Â’
. I have used iconv and also did try to do a str_replace('’','somechar',$row['data'])
but its now working.
It looks like all you need to do is echo $row['data'];
, the data is in Windows-1252 and your page's headers are in Windows-1252 as well. No conversion
to UTF-8 required.
If you didn't realize your data is in windows-1252, and so have set encoding="UTF-8"
in your xml, you shoiuld set it to encoding="Windows-1252"
.
If you want to use UTF-8, you should first start by setting your connection to UTF-8:
mysql_set_charset( "utf8" );
// or $mysqli->set_charset( "utf8" );
Before you make any queries.
After that you need to fix your http headers:
<?php
header( "Content-type: application/xml; charset=utf-8");
And of course, not call utf8_decode
. Never call utf8_decode
or utf8_encode
unless you really know what you're doing. For starters, these functions work on ISO-8859-1->UTF-8 (and vice versa) conversions (the real ISO-8859-1, not the browser "ISO-8859-1" which is actually just Windows-1252) and are not some magic unicode wand.
There are many other things to do if you want to take utf-8 route, but these two will fix your immediate problem.
这篇关于法语撇号字符在mysql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!