How can I convert an array to a SimpleXML object in PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Illegal to have multiple roots (start tag in epilo
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
other solution:
So anyway... I took onokazu's code (thanks!) and added the ability to have repeated tags in XML, it also supports attributes, hope someone finds it useful!
You may use xmlrpc_encode to create a xml from array if a verbose xml is not a problem. www.php.net/xmlrpc_encode
be careful the xml created differs in case you use associative and/or numeric keys
I wanted a code that will take all the elements inside an array and treat them as attributes, and all arrays as sub elements.
So for something like
I would get something like this
To achive this the code is below, but be very careful, it is recursive and may actually cause a stackoverflow :)
You may want to add checks for length of the array so that some element get set inside the data part and not as an attribute.
I found this solution similar to the original problem