XML strings, XML objects, inter-array conversions

Source: Internet
Author: User

<?phpnamespace Home\controller; UseThink\controller;classIndexcontrollerextendsController { Public functionindex () {$arr[' one '] = ' Hello '; $arr[' both '] = ' Hi '; $arr[' three '] = ' Hello '; $arr[' four '] = ' Ahan '; Dump ($arr); //arrays into XML strings        $curl _xml= Xml_encode ($arr, ' param '); Dump ($curl _xml); //XML strings into XML objects        $xml=simplexml_load_string($curl _xml); Dump ($xml); //XML object loaded into an XML string        $str=$xml-Asxml (); Dump ($str); //XML string Conversion array        $attr= Json_decode (Json_encode ($xml),TRUE); Dump ($attr); }}
Simplexml_load_string (): Gets the SimpleXMLElement object from the XML string (the function loads the XML string into the object) if it fails, it returns Falsesimplexml_load_file (string, Class,options,ns,is_prefix); string is required to specify the XML string to use, class is optional, the class of the new object is specified, the two methods are the same as getting the string, and the other is getting the file if (file_ Exists ('.. /common/timesmap.xml ') {$xml = ').  /common/timesmap.xml '; $str = file_get_contents ($xml);//convert XML file to XML string}

XML strings, XML objects, inter-array conversions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.