zoukankan      html  css  js  c++  java
  • xml字符串,xml对象,数组之间的相互转化

    
    
    <?php
    namespace HomeController;
    use ThinkController;
    class IndexController extends Controller {
    public function index(){
    $arr['one'] ='你好';
    $arr['two'] = 'hi';
    $arr['three'] = 'hello';
    $arr['four'] = 'ahan';

    dump($arr);

    //数组转换成xml字符串 ,$cur_xml字符串
    $curl_xml = xml_encode($arr, 'param');
    dump($curl_xml);

    //xml字符串转化成xml对象, $xml对象
    $xml = simplexml_load_string($curl_xml);
    dump($xml);

    //xml对象装换成xml字符串, 字符串$str
    $str = $xml->asXML();
    dump($str);

    //xml对象转化成数组 $shuzu数组
    $shuzu = json_decode(json_encode($xml),TRUE);
    dump($shuzu);
    }
    }
     
    simplexml_load_string():从xml字符串获取SimpleXMLElement对象(函数把XML字符串载入对象中)如果失败,则返回false
    simplexml_load_file(string,class,options,ns,is_prefix);string是必须填写,规定使用的XML字符串,class可选,规定新对象的class,两个方法大同小异一个是获取字符串,另一个是获取文件
    if(file_exists('../Common/timesmap.xml'))
    {
      $xml = '../Common/timesmap.xml';
      $str = file_get_contents($xml);//将xml文件转化成xml字符串
    }
     
     
  • 相关阅读:
    oracle 11g 数据库密码大小写敏感性更改
    OGG 课程 第一课
    xmanager
    一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + 物理 dg
    GTONE安装Eclipse插件
    JDK安装与环境变量配置
    JAVA基础
    操作符总结
    物理CPU查看方式
    SQL SERVER性能调优
  • 原文地址:https://www.cnblogs.com/Duriyya/p/5942795.html
Copyright © 2011-2022 走看看