如何使用php读出<?xml version="1.0" encoding="utf-8"?> <!-- - phpMyAdmin XML Dump - version 4.8.5 - https://www.phpmyadmin.net - - 主机: localhost - 生成日期: 2023-05-30 10:05:02 - 服务器版本: 5.7.26 - PHP 版本: 7.3.4 --> <pma_xml_export version="1.0" xmlns:pma="https://www.phpmyadmin.net/some_doc_url/"> <!-- - Structure schemas --> <pma:structure_schemas> <pma:database name="xmlrd" collation="utf8_unicode_ci" charset="utf8"> <pma:table name="xmlrd"> CREATE TABLE `xmlrd` ( `id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `ys` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `ks` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; </pma:table> </pma:database> </pma:structure_schemas> <!-- - 数据库: 'xmlrd' --> <database name="xmlrd"> <!-- 表 xmlrd --> <table name="xmlrd"> <column name="id">001</column> <column name="ys">张三</column> <column name="ks">呼吸内科</column> </table> </database> </pma_xml_export>中table的内容
时间: 2024-02-20 22:56:40 浏览: 168
你可以使用SimpleXMLElement来解析XML并读取table的内容,示例代码如下:
```
$xml_string = '<?xml version="1.0" encoding="utf-8"?>
<pma_xml_export version="1.0" xmlns:pma="https://www.phpmyadmin.net/some_doc_url/">
<!-- - Structure schemas -->
<pma:structure_schemas>
<pma:database name="xmlrd" collation="utf8_unicode_ci" charset="utf8">
<pma:table name="xmlrd">
CREATE TABLE `xmlrd` (
`id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`ys` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`ks` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
</pma:table>
</pma:database>
</pma:structure_schemas>
<!-- - 数据库: 'xmlrd' -->
<database name="xmlrd">
<!-- 表 xmlrd -->
<table name="xmlrd">
<column name="id">001</column>
<column name="ys">张三</column>
<column name="ks">呼吸内科</column>
</table>
</database>
</pma_xml_export>';
$xml = new SimpleXMLElement($xml_string);
$table_content = $xml->database->table->asXML();
echo $table_content;
```
这段代码会输出类似下面的XML内容:
```
<table name="xmlrd">
<column name="id">001</column>
<column name="ys">张三</column>
<column name="ks">呼吸内科</column>
</table>
```
阅读全文