<?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
関連記事
![cURL はどのように PHP での HTTP リクエストを容易にするのですか?](https://img.php.cn/upload/article/001/246/273/173289625287748.jpg)
30 Nov 2024
cURL: PHP の HTTP リクエスト ハンドラー PHP 開発の分野では、「cURL」という用語が頻繁に登場します。それは図書館です...
![App Engine 上の Golang アプリケーションでパスワードを保護するにはどうすればよいですか?](https://img.php.cn/upload/article/001/246/273/173030193117363.jpg)
30 Oct 2024
App Engine 上の Golang でパスワードを保護するWeb アプリケーションのパスワード ハッシュに関しては、セキュリティが最も重要です。人気の図書館ですが...
![iTextSharp を使用してテキストの書式設定情報 (フォント、サイズなど) を抽出するにはどうすればよいですか?](https://img.php.cn/upload/article/001/246/273/173655976762177.jpg)
11 Jan 2025
iTextSharp でテキストの書式設定を行うにはどうすればよいですか?はい、iTextSharp でテキストの書式設定を行うことができます。図書館では次のようなサービスを提供しています...
![プレーンな JavaScript を使用してテキストから HTML タグを効率的に削除する方法](https://img.php.cn/upload/article/001/246/273/173525467432390.jpg)
27 Dec 2024
プレーン JavaScript のテキストから HTML タグを削除する文字列から HTML タグを削除することは、Web 開発における一般的なタスクです。図書館もあるのに…
![システム設計: 図書館管理システム](https://img.php.cn/upload/article/001/246/273/173042649171859.jpg)
01 Nov 2024
Go でライブラリ管理システムを構築する この記事では、Go に実装されたライブラリ管理システム (LMS) について調べて、その中核的な機能、設計上の決定事項、主要なコード スニペットに焦点を当てましょう。 図書館管理の主要な機能
![PHP を使用してデータを JSON 形式に変換するには?](https://img.php.cn/upload/article/001/246/273/172934682340879.jpg)
19 Oct 2024
PHP で JSON データを生成する方法 PHP で JSON データを生成するには、json_encode() などの強力な関数を利用できます。この関数は、配列などのデータ構造を JSON 文字列に変換します。データベースベースの JSON 生成のシナリオを考えてみましょう。
![](/static/imghw/down_right.png)
![](/static/imghw/taglogo.png)
ホットツール Tags
![](/static/imghw/taglogo.png)
Hot Tools
![依存関係注入コンテナー用の PHP ライブラリ](https://img.php.cn/upload/manual/000/000/001/5e2171bf3c005481.png)
依存関係注入コンテナー用の PHP ライブラリ
依存関係注入コンテナー用の PHP ライブラリ
50 個の優れた古典的な PHP アルゴリズムのコレクション
古典的な PHP アルゴリズム、優れたアイデアを学び、思考を広げます
画像を最適化するための小さな PHP ライブラリ
画像を最適化するための小さな PHP ライブラリ
![](/static/imghw/taglogo.png)