国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 PHP 庫 其它類庫 PHP數據格式與XML進行轉換類
PHP數據格式與XML進行轉換類
<?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和數據格式中互相轉換的類庫,需要的朋友可以下載使用。

免責聲明

本站所有資源均由網友貢獻或各大下載網站轉載。請自行檢查軟件的完整性!本站所有資源僅供學習參考。請不要將它們用于商業(yè)目的。否則,一切后果由您負責!如有侵權,請聯(lián)系我們刪除。聯(lián)系方式:admin@php.cn

相關文章

在將漢字數據轉換為JSON格式時,什么時候需要進行Unicode轉換? 在將漢字數據轉換為JSON格式時,什么時候需要進行Unicode轉換?

01 Apr 2025

漢字數據轉JSON時Unicode轉換的時機探討在處理包含漢字的數據時,將其轉換為JSON格式并存儲是一個常見需求。然...

LINQ 如何有效地將數據從寬格式轉換為高格式以進行網格顯示? LINQ 如何有效地將數據從寬格式轉換為高格式以進行網格顯示?

05 Jan 2025

使用 LINQ 透視數據在數據科學中,透視將數據從寬格式轉換為高格式,反之亦然。假設您有一個數據集...

如何在 PHP 中將列式數據結構轉換為基于行的格式? 如何在 PHP 中將列式數據結構轉換為基于行的格式?

25 Oct 2024

將多維列式數據重新排序為基于行的結構給定一個具有面向列數據的關聯(lián)數組,任務是轉置...

如何使用自連接從自引用表中檢索數據? 如何使用自連接從自引用表中檢索數據?

13 Jan 2025

了解 SELF JOIN 及其應用程序在數據庫管理領域中,SELF JOIN 是一種特殊類型的聯(lián)接操作,它允許...

在 Joomla 中連接第三方 PHP 庫 在 Joomla 中連接第三方 PHP 庫

28 Dec 2024

PHP 庫很方便,因為可以從應用程序中的任何位置訪問它們:從插件、組件模型、模塊等。如果有人已經解決了類似的問題并將其設計為庫(甚至更新了它),那就有意義了

Oracle 數據庫現在支持布爾數據類型嗎? Oracle 數據庫現在支持布爾數據類型嗎?

12 Jan 2025

Oracle 數據庫中布爾數據類型的可用性與其他 RDBMS(例如提供 BIT 數據類型的 Microsoft SQL Server)不同,Oracle 數據庫...

See all articles