Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mysql在php中创建xml字符_Php_Mysql_Xml_Unicode - Fatal编程技术网

从mysql在php中创建xml字符

从mysql在php中创建xml字符,php,mysql,xml,unicode,Php,Mysql,Xml,Unicode,我的php文件使用mysql数据库中的数据创建XML,我的数据库中有一些特殊字符,无法正确显示。s PHP代码: SQL表结构、数据和证明: 链接: 请帮我解决这个问题,我已经经历了stackoverflow,并尝试了几种方法,但没有人成功 谢谢,XMLWriter是用于结果列表的标准XML API,就像数据库结果一样。它以线性方式工作,保持内存使用率低 XMLWriter根据需要处理转义。确保已将数据库连接的编码设置为utf-8 $records = [ [ 'questioni

我的php文件使用mysql数据库中的数据创建XML,我的数据库中有一些特殊字符,无法正确显示。s

PHP代码:

SQL表结构、数据和证明:

链接:

请帮我解决这个问题,我已经经历了stackoverflow,并尝试了几种方法,但没有人成功


谢谢,

XMLWriter是用于结果列表的标准XML API,就像数据库结果一样。它以线性方式工作,保持内存使用率低

XMLWriter根据需要处理转义。确保已将数据库连接的编码设置为utf-8

$records = [
  [
    'questionid' => '1',
    'item' => 'one'
  ],
  [
    'questionid' => '2',
    'item' => 'two'
  ]
];

header('Content-type: text/xml; charset: utf-8');
$out = new XMLWriter();
$out->openURI('php://output');
$out->setIndent(true);
$out->startDocument('1.0', 'UTF-8');
$out->startElement('quiz');

while (list($key, $record) = each($records)) {
  $out->startElement('question');
  $out->writeAttribute('id', $record['questionid']);
  $out->writeElement('item', $record['item']);
  $out->endElement();
}

$out->endElement();
输出:

<?xml version="1.0" encoding="UTF-8"?>
<quiz>
 <question id="1">
  <item>one</item>
 </question>
 <question id="2">
  <item>two</item>
 </question>
</quiz>

一
二

您好,谢谢您的回答,当我直接使用“引号”提供字符时,它会工作,但当我从数据库检索数据并显示时,它会显示吗?做记号谢谢,你检查过数据库连接编码了吗?您好,我已经将数据库连接编码更改为utf8\u general\u ci,仍然是吗?标记:/IDK如果在数据库ui(phpMyAdmin)中打开表,字符串是否正确?如果编码错误,它们可能会在保存时被销毁。如果不访问您的系统,这很难进行调试,但是这个答案可能会帮助您:非常感谢您的帮助,这个XMLWriter帮了我很多。这是解决问题的关键,我已经解决了。谢谢