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

Home PHP Libraries Other libraries PHP data format and XML conversion class
PHP data format and XML conversion class
<?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
    }

This is a class library that can convert between XML and data formats. Friends who need it can download and use it.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

How Can LINQ to XML Efficiently Parse and Format Nested XML Data? How Can LINQ to XML Efficiently Parse and Format Nested XML Data?

30 Jan 2025

LINQ to XML: Reading and Manipulating XML DataWhen working with XML data in .NET, LINQ to XML offers a powerful and flexible approach to querying...

Dynamic data type conversion: PHP array element type intelligent recognition and conversion Dynamic data type conversion: PHP array element type intelligent recognition and conversion

27 Aug 2025

This article introduces an effective method to dynamically convert array values ??of string types into their corresponding data types (such as integers, floating point numbers, and boolean values) in PHP. In response to the problem of inefficient manual conversion when processing large amounts of or dynamic data, practical skills are provided to use json_encode combined with JSON_NUMERIC_CHECK and filter_var functions for type inference and conversion, and the advantages and disadvantages of different solutions are compared, aiming to help developers choose the most suitable solution for their own scenarios and improve data processing efficiency.

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

Process XML responses and extract data using PHP Guzzle Process XML responses and extract data using PHP Guzzle

27 Aug 2025

This article describes how to use the PHP Guzzle library to send HTTP requests and extract the required data from the XML response. It focuses on how to process XML data containing namespaces and provides sample code to parse XML data using SimpleXMLElement to help developers quickly and efficiently extract specific fields in XML data.

How to Send HTTP GET Requests and Retrieve XML Data in PHP? How to Send HTTP GET Requests and Retrieve XML Data in PHP?

01 Dec 2024

Sending GET Requests in PHPQuestion: How can I send an HTTP GET request to retrieve XML content from a URL using PHP?Answer:To download XML...

How to Parse XML Responses from PHP cURL Efficiently and Extract Data? How to Parse XML Responses from PHP cURL Efficiently and Extract Data?

28 Oct 2024

Retrieve XML Responses with PHP cURL and Extract Data EfficientlyWhen using PHP cURL to interact with servers, it's common to receive XML...

See all articles