<?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
関連記事
30Nov2024
cURL: PHP の HTTP リクエスト ハンドラー PHP 開発の分野では、「cURL」という用語が頻繁に登場します。それは図書館です...
30Oct2024
App Engine 上の Golang でパスワードを保護するWeb アプリケーションのパスワード ハッシュに関しては、セキュリティが最も重要です。人気の図書館ですが...
11Jan2025
iTextSharp でテキストの書式設定を行うにはどうすればよいですか?はい、iTextSharp でテキストの書式設定を行うことができます。図書館では次のようなサービスを提供しています...
27Dec2024
プレーン JavaScript のテキストから HTML タグを削除する文字列から HTML タグを削除することは、Web 開発における一般的なタスクです。図書館もあるのに…
19Oct2024
PHP で JSON データを生成する方法 PHP で JSON データを生成するには、json_encode() などの強力な関数を利用できます。この関数は、配列などのデータ構造を JSON 文字列に変換します。データベースベースの JSON 生成のシナリオを考えてみましょう。
01Nov2024
Go でライブラリ管理システムを構築する この記事では、Go に実装されたライブラリ管理システム (LMS) について調べて、その中核的な機能、設計上の決定事項、主要なコード スニペットに焦点を当てましょう。 図書館管理の主要な機能
Hot Tools
依存関係注入コンテナー用の PHP ライブラリ
依存関係注入コンテナー用の PHP ライブラリ
50 個の優れた古典的な PHP アルゴリズムのコレクション
古典的な PHP アルゴリズム、優れたアイデアを学び、思考を広げます
画像を最適化するための小さな PHP ライブラリ
画像を最適化するための小さな PHP ライブラリ