UTF-8,PHP和XML Mysql [英] UTF-8, PHP and XML Mysql

查看:146
本文介绍了UTF-8,PHP和XML Mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个mysql数据库编码latin1_swedish_ci和一个存储名称和地址的表。



我正在尝试输出一个UTF-8 XML文件,但是我遇到以下字符串的问题:



Otivägen当我维护文件时,它被输出为Otivägen。另外当打开它IE IE get



在文本内容中找到一个无效的字符错误处理资源



我有以下代码:

  function fixEncoding($ in_str) 
{
$ cur_encoding = mb_detect_encoding($ in_str);
if($ cur_encoding ==UTF-8&& mb_check_encoding($ in_str,UTF-8))
return $ in_str;
else
return utf8_encode($ in_str);
}

header(Content-type:text / plain; charset = utf-8);
$ mystring =Otivägen//这实际上是从数据库获取的;

$ myxml =< myxml>
....
< node>$ mystring。< / node>
... 。
< / myxml>
;
$ myxml = fixEncoding($ myxml);

实际的XML输出如下:

 <?xml version =1.0encoding =UTF-8?> 
< myxml>
....
< node>Otivägen< / node>
....
< / myxml>

任何想法,我可以输出文件,所以在vim文件中读取Otivägen 而不是Otivägen



编辑:



我做了 mysql_client_encoding()并得到 latin1 br />
然后我做了 mysql_set_charset()

并再次运行 mysql_client_encoding()并获得utf8,但仍然输出相同的问题。



编辑2



我已经登录到命令行并运行查询 SELECT address1 FROM address WHERE id = 1000;

  SELECT address1 FROM address WHERE id = 1000; 
当前数据库:ftpuser_db

+ ------------- +
| address1 |
+ ------------- +
| Otivägen32 |
+ ------------- +
1行集(0.06秒)

提前感谢

解决方案

我认为你做的一切正确,在拉丁文-1中。



ä的UTF-8序列为C3 A4,如果显示为拉丁文-1,则为¤。


I am having great problems solving this one:

I have a mysql database encoding latin1_swedish_ci and a table that stores names and addresses.

I am trying to output a UTF-8 XML file, but I am having problems with the following string:

Otivägen it is being outputted as Otivägen when i vim the file. Also when opened it IE i get

"An invalid character was found in text content. Error processing resource"

I have the following code:

function fixEncoding($in_str)
{
    $cur_encoding = mb_detect_encoding($in_str) ;
    if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
        return $in_str;
    else
        return utf8_encode($in_str);
}

header("Content-type: text/plain;charset=utf-8");
$mystring = "Otivägen" // this is actually obtained from database;

$myxml = "<myxml>
....
     <node>".$mystring."</node>
....
</myxml>
";
$myxml = fixEncoding($myxml);

The actual XML output is below:

<?xml version="1.0" encoding="UTF-8" ?>
<myxml>
    ....
    <node>Otivägen</node>
    ....
</myxml>

Any ideas how I can output the file so in vim the file reads Otivägen and not Otivägen?

EDIT:

I did mysql_client_encoding() and got latin1
I then did mysql_set_charset()
and again ran mysql_client_encoding() and got utf8, but still the same outputting issues.

Edit 2

I have logged into the command line and run the query SELECT address1 FROM address WHERE id = 1000;

SELECT address1 FROM address WHERE id = 1000;
Current database: ftpuser_db

+-------------+
|   address1  |
+-------------+
| Otivägen 32 |
+-------------+
1 row in set (0.06 sec)

Thanks in advance!

解决方案

I think you did everything correctly, except that your terminal is in Latin-1.

The UTF-8 sequence for ä is C3 A4, which is ä if displayed as Latin-1.

这篇关于UTF-8,PHP和XML Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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