zoukankan      html  css  js  c++  java
  • php将xml文件转化为数组:simplexml_load_string

    <?php
    $str = <<<XML
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
        <book>
            <category>COOKING</category>
            <title>Everyday Italian</title>
            <author>Giada De Laurentiis</author>
            <year>2005</year>
            <price>30.00</price>
        </book>
        <book>
            <category>CHILDREN</category>
            <title>Harry Potter</title>
            <author>J K. Rowling</author>
            <year>2005</year>
            <price>29.99</price>
        </book>
        <book>
            <category>WEB</category>
            <title>Learning XML</title>
            <author>Erik T. Ray</author>
            <year>2003</year>
            <price>39.95</price>
        </book>
    
        <news>
            <category>CHILDREN</category>
            <title>Harry Potter</title>
            <author>J K. Rowling</author>
            <year>2005</year>
            <price>29.99</price>
        </news>
        <news>
            <category>WEB</category>
            <title>Learning XML</title>
            <author>Erik T. Ray</author>
            <year>2003</year>
            <price>39.95</price>
        </news>
    
        <blog>
            <category>CHILDREN</category>
            <title>Harry Potter</title>
            <author>J K. Rowling</author>
            <year>2005</year>
            <price>29.99</price>
        </blog>
        <blog>
            <category>WEB</category>
            <title>Learning XML</title>
            <author>Erik T. Ray</author>
            <year>2003</year>
            <price>39.95</price>
        </blog>
    </note>
    XML;
    
    $strObj = simplexml_load_string($str);
    $json = json_encode($strObj);
    $ary = json_decode($json, true);
    
    echo '<pre>';
    print_r($ary);
    echo '</pre>';
  • 相关阅读:
    第02组 Beta冲刺(4/5)
    第02组 Beta冲刺(3/5)
    第02组 Beta冲刺(2/5)
    第02组 Beta冲刺(1/5)
    第02组 Alpha事后诸葛亮
    第02组 Alpha冲刺(6/6)
    第02组 Alpha冲刺(5/6)
    第02组 Alpha冲刺(4/6)
    第02组 Alpha冲刺(3/6)
    2020系统综合实践1 微服务与Docker 基本入门
  • 原文地址:https://www.cnblogs.com/intval/p/3616180.html
Copyright © 2011-2022 走看看