更多>
最新下载
24小时阅读排行榜
- 1 Go 中切片的容量机制:为什么 append 能突破初始 cap 限制?
- 2 c# System.IO.Pipelines 和 NetworkStream 的性能对比
- 3 GraphQL查询结果如何映射到XML
- 4 css 想让输入框在 focus 时高亮怎么办_使用 css tailwind focus 工具类
- 5 c++高频交易(HFT)系统开发有哪些性能优化要点? (低延迟编程)
- 6 如何在 Nuxt 2 中正确使用 emit 实现父子组件通信
- 7 WCF服务中的XML序列化怎么配置 DataContractSerializer
- 8 如何让 Flex 布局中左侧 div 随右侧内容自动等高填充背景色
- 9 css flexbox 布局实现响应式设计_自动排列页面元素
- 10 mysql表继承怎么做_mysql面向对象设计方案解析
- 11 如何将 HTML 输入字段转换为可交互的段落元素并实现焦点切换
- 12 如何在 Pandas DataFrame 开头补全缺失时间戳并统一插值降频
- 13 Laravel中如何定义模型范围Scopes_Laravel本地作用域Scope使用方法【详解】
- 14 Golang使用context控制网络请求生命周期
- 15 css 想快速实现手风琴折叠菜单怎么办_利用 css bootstrap collapse 组件
更多>
最新教程
-
- Node.js 教程
- 15532 2025-08-28
-
- CSS3 教程
- 1544718 2025-08-27
-
- Rust 教程
- 22811 2025-08-27
-
- Vue 教程
- 25287 2025-08-22
-
- PostgreSQL 教程
- 21861 2025-08-21
-
- Git 教程
- 8876 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
