更多>
最新下载
24小时阅读排行榜
- 1 css元素阴影平滑过渡如何实现_利用transition-box-shadow实现
- 2 css颜色需要半透明但不影响子元素怎么办_使用rgba颜色替代opacity
- 3 如何使用Golang实现TCP客户端_Golang net Dial与Read方法实践
- 4 php数据统计图表能导出图片吗_php用jpgraph导出图表法【技巧】
- 5 mysql中的GRANT语句与权限授予方法
- 6 Open Policy Agent (OPA) 如何为XML上传接口定义访问策略
- 7 mysql备份和恢复有什么区别_mysql数据安全管理解析
- 8 css 想让网格容器内容居中怎么办_justify-content center align-content center
- 9 C# 图片压缩方法 C#如何实现图片大小压缩
- 10 php二维数组转一维生成序列_php二维降维生成连续序号【方法】
- 11 css border 不显示是什么原因_边框属性常见问题排查
- 12 什么是AJAX以及如何在javascript中实现_怎样与服务器进行异步通信【教程】
- 13 html5播放rtsp怎么投屏_html5rtsp投屏电视方法【扩展】
- 14 css grid布局中隐式网格是怎么产生的_通过自动扩展规则说明
- 15 javascript如何操作JSON数据?_如何进行JSON字符串和对象的相互转换?【教程】
更多>
最新教程
-
- Node.js 教程
- 16309 2025-08-28
-
- CSS3 教程
- 1546999 2025-08-27
-
- Rust 教程
- 23432 2025-08-27
-
- Vue 教程
- 25871 2025-08-22
-
- PostgreSQL 教程
- 22370 2025-08-21
-
- Git 教程
- 9321 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
