更多>
最新下载
24小时阅读排行榜
- 1 C#怎么用XmlReader逐行读取大型XML文件
- 2 html如何变成三角形_用CSS将HTML元素变成三角形【变成】
- 3 SQL动态拼接条件安全吗_风险分析与改进技巧【技巧】
- 4 EF Core Attach和Update有什么区别 EF Core实体状态跟踪详解
- 5 SQL大促场景如何扛压_限流与降级策略说明【教程】
- 6 Linux内存泄漏怎么排查_free与vmstat解析【教学】
- 7 JavaScript的this关键字如何工作?
- 8 SQL任务重试记录机制_SQL保证最终一致方案
- 9 css如何将元素转成块级显示_使用display block改变元素特性
- 10 javascript如何运行_它如何通过事件循环处理异步任务
- 11 C#如何将XML文件打包为独立部署的资源
- 12 如何配置mysql环境变量_mysql环境变量设置方法
- 13 SQL统计实时指标怎么做_近实时查询方案解析【技巧】
- 14 css透明度变化出现闪现怎么办_确保transition作用于opacity
- 15 C++如何使用Google Test框架进行单元测试?(GTest入门)
更多>
最新教程
-
- Node.js 教程
- 14088 2025-08-28
-
- CSS3 教程
- 1540596 2025-08-27
-
- Rust 教程
- 21788 2025-08-27
-
- Vue 教程
- 24307 2025-08-22
-
- PostgreSQL 教程
- 21029 2025-08-21
-
- Git 教程
- 8287 2025-08-21
下载首页 / 类库下载 / 其它类库
<?php
function xml2array($contents, $get_attributes = 1, $priority = 'tag') {
if (!$contents) return array();
if (!function_exists('xml_parser_create')) {
// print "'xml_parser_create()' function not found!";
return array();
}
// Get the XML parser of PHP - PHP must have this module for the parser to work
$parser = xml_parser_create('');
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($contents), $xml_values);
xml_parser_free($parser);
if (!$xml_values) return; //Hmm...
// Initializations
$xml_array = array();
$parents = array();
$opened_tags = array();
$arr = array();
$current = &$xml_array; //Refference
// Go through the tags.
$repeated_tag_index = array(); //Multiple tags with same name will be turned into an array
foreach($xml_values as $data) {
unset($attributes, $value); //Remove existing values, or there will be trouble
// This command will extract these variables into the foreach scope
// tag(string), type(string), level(int), attributes(array).
extract($data); //We could use the array by itself, but this cooler.
$result = array();
$attributes_data = array();
if (isset($value)) {
if ($priority == 'tag') $result = $value;
else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
}这是一个可以在XML和数据格式中互相转换的类库,需要的朋友可以下载使用。
本站所有资源都是由网友投搞发布,或转载各大下载站,请自行检测软件的完整性!本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!如有侵权请联系我们删除下架,联系方式:admin@php.cn
