从SQL的XML输出字符集..德文字符..我哪里错了? [英] Charset in XML output from SQL .. german characters .. where am I going wrong?

查看:131
本文介绍了从SQL的XML输出字符集..德文字符..我哪里错了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您抽出宝贵时间!

我正在尝试将地图应用程序放在一起以测试Google Maps V3 API。这也是我第一次用PHP / SQL输出XML,然后处理结果。

I am trying to put together a mapping app to experiment with the Google Maps V3 API. It is also my first time outputting XML with PHP/SQL and then processing the results.

我用这个作为我的指南>> http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html

I am using this as my guide >> http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html

我的问题是当我使用包含德语地址/字符的SQL表时,它不起作用 - 我得到这个错误给我

My problem is when I use a SQL table containing German addresses/characters, it doesn't work -- I get this error thrown to me

This page contains the following errors:

error on line 2 at column 1: Extra content at the end of the document 

..并检查页面源代码我看到...

..and examining the page source I see this...

<b>Warning</b>:  DOMElement::setAttribute() [<a href='domelement.setattribute'>domelement.setattribute</a>]: string is not in UTF-8 in <b>/Applications/MAMP/htdocs/guruTest/guruTest.php</b> on line <b>46</b><br />
<br />
<b>Warning</b>:  DOMDocument::saveXML() [<a  href='domdocument.savexml'>domdocument.savexml</a>]: output conversion failed due to conv  error, bytes 0xDF 0x65 0x20 0x33 in <b>/Applications/MAMP/htdocs/guruTest/guruTest.php</b>  on line <b>52</b><br />
<?xml version="1.0" ?>
<markers>

使用相同的PHP / SQL,但切换到英文地址数据库时,它工作正常。所以看起来问题在于德语地址中的德语字符。

Using the same PHP/SQL but switching to a database of English addresses, it works fine. So it seems the problem is the German characters in my German addresses.

我最初是从code.google.com上看到的代码。在那个例子中,XML文档没有给出字符集。

I had originally started with the code pretty much as you see on code.google.com. In that example, no charset is given for the XML document.

这是我认为问题出在哪里

Here is where I think the problem is

$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['name']);

当我用德语信息看到错误时,我在头部声明中加入了编码。简单地这样做...

When I started seeing the errors with my German info I added encoding to the head declaration. Simply by doing this...

header("Content-type: text/xml; charset: UTF-8");

但是我错误缠身的XML输出仍然显示

But my error-ridden XML output was still showing

<?xml version="1.0" encoding="ISO-8859-1"?>

..所以..我显然完全不知道我在做什么。

.. so .. I clearly have absolutely no idea what I'm doing.

任何人都想帮忙吗?

Anyone want to help out?

推荐答案

使用这个字符串函数当你传递变量时:

Use this string function while you pass the variable:

utf8_encode($variable);

这篇关于从SQL的XML输出字符集..德文字符..我哪里错了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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