-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSerializer.class.php
56 lines (50 loc) · 1.3 KB
/
Serializer.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/****
* @PHPVER4.0
*
* @author emnu
* @ver --
* @date 12/08/08
*
* use this class to convert from mutidimensional array to xml.
* see example.php file on howto use this class
*
*/
class arr2xml
{
var $array = array();
var $xml = '';
function arr2xml($array, $insertCabecalho = true)
{
$this->array = $array;
if (is_array($this->array) && count($this->array) > 0) {
if ($insertCabecalho == true) {
$this->xml .= '<?xml version="1.0" encoding="UTF-8"?>';
}
$this->xml .= "<full>";
$this->struct_xml($array);
$this->xml .= "</full>";
} else {
$this->xml .= "no_data";
}
}
function struct_xml($array)
{
foreach ($array as $k => $v) {
if (is_array($v)) {
$tag = preg_replace('/[0-9]{1,}/', 'data', $k); // replace numeric key in array to 'data'
$this->xml .= "<$tag>";
$this->struct_xml($v);
$this->xml .= "</$tag>";
} else {
$tag = preg_replace('/[0-9]{1,}/', 'data', $k); // replace numeric key in array to 'data'
$this->xml .= "<$tag>$v</$tag>";
}
}
}
function get_xml()
{
echo $this->xml;
}
}
?>