PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 3.3.2
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v3.3.2
3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / classes / arraytoxml.php
wp-all-import / classes Last commit date
PHPExcel 10 years ago PHPExcel.php 10 years ago api.php 10 years ago arraytoxml.php 10 years ago chunk.php 10 years ago config.php 10 years ago download.php 10 years ago handler.php 10 years ago helper.php 10 years ago input.php 10 years ago render.php 10 years ago session.php 10 years ago upload.php 10 years ago
arraytoxml.php
62 lines
1 <?php
2
3 class PMXI_ArrayToXML
4 {
5 /**
6 * The main function for converting to an XML document.
7 * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
8 *
9 * @param array $data
10 * @param string $rootNodeName - what you want the root node to be - defaultsto data.
11 * @param SimpleXMLElement $xml - should only be used recursively
12 * @return string XML
13 */
14 public static function toXml($data, $rootNodeName = 'data', $xml=null, $lvl = 0)
15 {
16 // turn off compatibility mode as simple xml throws a wobbly if you don't.
17 if (ini_get('zend.ze1_compatibility_mode') == 1)
18 {
19 ini_set ('zend.ze1_compatibility_mode', 0);
20 }
21
22 if ($xml == null)
23 {
24 $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><'.$rootNodeName .'/>');
25 }
26 if ( !empty($data)){
27 // loop through the data passed in.
28 foreach($data as $key => $value)
29 {
30 // no numeric keys in our xml please!
31 if (!$key or is_numeric($key))
32 {
33 // make string key...
34 $key = "item_" . $lvl;
35
36 }
37
38 // replace anything not alpha numeric
39 $key = preg_replace('/[^a-z0-9_]/i', '', $key);
40
41 // if there is another array found recrusively call this function
42 if (is_array($value) or is_object($value))
43 {
44 $node = $xml->addChild($key);
45 // recrusive call.
46 PMXI_ArrayToXML::toXml($value, $rootNodeName, $node, $lvl + 1);
47 }
48 else
49 {
50 // add single node.
51 $value = htmlspecialchars($value);
52 $xml->addChild($key,$value);
53 }
54
55 }
56 }
57 // pass back as string. or simple xml object if you want!
58 return $xml->asXML();
59 }
60
61
62 }