V.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?php
  2. /**
  3. * @see http://pl2.php.net/manual/en/book.var.php
  4. *
  5. * Define Your own convert function: var func_type_convert_{$type}($var);
  6. */
  7. class V {
  8. /**
  9. * Get variable from array or object - case insensitive
  10. */
  11. public static function geti($name, $default, $from, $type = '', $filterCallback = null) {
  12. $lowerFrom = array();
  13. if (!is_object($from) && !is_array($from)) throw new Exception("Bad param - from must be array or object");
  14. foreach ((array)$from as $fieldName => $value) {
  15. $lowerFrom[ strtolower($fieldName) ] = $value;
  16. }
  17. return V::get(strtolower($name), $default, $lowerFrom, $type, $filterCallback);
  18. }
  19. /**
  20. * Get variable from array or object.
  21. */
  22. public static function get($name, $default, $from, $type = '', $filterCallback = null) {
  23. if (empty($name)) return null;
  24. $ret = null;
  25. if (is_bool($name)) $name = (int)$name;
  26. if (!is_string($name) && !is_numeric($name)) {
  27. //var_dump($name);
  28. //echo'<pre>';print_r(debug_backtrace());echo'</pre>';
  29. throw new Exception("Error name is not scalar! '{$name}'");
  30. }
  31. if (is_array($from)) {
  32. if (array_key_exists($name, $from)) {
  33. $ret = $from[$name];
  34. }
  35. }
  36. else if (is_object($from)) {
  37. if (isset($from->$name)) {
  38. $ret = $from->$name;
  39. }
  40. }
  41. if (isset($ret) && $type != '') {
  42. $ret = V::convert($ret, $type);
  43. }
  44. if (!empty($filterCallback)) {
  45. if ($type == 'array' && is_array($ret) && !empty($ret)) {
  46. $ret = V::filter($ret, $filterCallback);
  47. }
  48. }
  49. $ret = (null !== $ret)? $ret : $default;
  50. return $ret;
  51. }
  52. /**
  53. * Convert variable type.
  54. * @usage: V::convert($from, 'url');
  55. */
  56. public static function convert($from, $type = 'string') {
  57. $type = strtolower($type);
  58. // is_scalar($from) - return TRUE if int,float,string,bool, FALSE if array,object,resource, ...
  59. $ret = null;
  60. switch ($type) {
  61. case 'string':
  62. if (is_scalar($from)) {
  63. $ret = $from;
  64. settype($ret, $type);
  65. }
  66. break;
  67. case 'word':
  68. if (is_scalar($from)) {
  69. $ret = $from;
  70. settype($ret, 'string');
  71. $ret = trim($ret);
  72. if (false !== ($pos = strpos($ret, ' '))) {
  73. $ret = substr($ret, 0, $pos);
  74. }
  75. }
  76. break;
  77. case 'login':// [a-zA-Z.-_]
  78. if (is_scalar($from)) {
  79. $ret = $from;
  80. settype($ret, 'string');
  81. $ret = trim($ret);
  82. if (!preg_match("/^[a-zA-Z.-_]*$/", $ret, $matches)) {
  83. $ret = null;
  84. }
  85. }
  86. break;
  87. case 'url':// [a-zA-Z0-9_-]
  88. if (is_scalar($from)) {
  89. $ret = $from;
  90. settype($ret, 'string');
  91. $ret = trim($ret);
  92. $pl_letters = array('ą', 'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ź', 'ż', 'Ą', 'Ć', 'Ę', 'Ł', 'Ń', 'Ó', 'Ś', 'Ź', 'Ż');
  93. $en_letters = array('a', 'c', 'e', 'l', 'n', 'o', 's', 'z', 'z', 'A', 'C', 'E', 'L', 'N', 'O', 'S', 'Z', 'Z');
  94. $ret = str_replace($pl_letters, $en_letters, $ret);
  95. $ret = preg_replace('/[^a-zA-Z0-9_-]+/', '_', $ret);
  96. }
  97. break;
  98. case 'int':
  99. case 'integer':
  100. if (is_scalar($from)) {
  101. $ret = $from;
  102. settype($ret, $type);
  103. }
  104. break;
  105. case 'float':
  106. case 'double':
  107. if (is_scalar($from)) {
  108. $ret = str_replace(',', '.', $from);
  109. settype($ret, $type);
  110. }
  111. break;
  112. case 'price':// 0.00 - decimal(n, 2)
  113. if (is_scalar($from)) {
  114. $ret = str_replace(',', '.', $from);
  115. settype($ret, 'float');
  116. $ret = round($ret, 2);
  117. }
  118. break;
  119. case 'object':
  120. case 'array':
  121. if (is_scalar($from) || is_array($from) || is_object($from)) {
  122. $ret = $from;
  123. settype($ret, $type);
  124. }
  125. break;
  126. case 'int_array':
  127. if (is_scalar($from) || is_array($from) || is_object($from)) {
  128. $ret = array();
  129. $arr = $from;
  130. settype($arr, 'array');
  131. foreach ($arr as $v) {
  132. $v = V::convert($v, 'int');
  133. $ret[] = $v;
  134. }
  135. }
  136. break;
  137. case 'uint_array':// uncigned int array
  138. if (is_scalar($from) || is_array($from) || is_object($from)) {
  139. $ret = array();
  140. $arr = $from;
  141. settype($arr, 'array');
  142. foreach ($arr as $v) {
  143. $v = V::convert($v, 'int');
  144. if ($v <= 0) continue;
  145. $ret[] = $v;
  146. }
  147. }
  148. break;
  149. case 'float_array':// uncigned int array
  150. if (is_scalar($from) || is_array($from) || is_object($from)) {
  151. $ret = array();
  152. $arr = $from;
  153. settype($arr, 'array');
  154. foreach ($arr as $v) {
  155. $v = V::convert($v, 'float');
  156. $ret[] = $v;
  157. }
  158. }
  159. break;
  160. default:
  161. $fun = 'func_type_convert_'.$type;
  162. if (function_exists($fun)) {
  163. $ret = $fun($from);
  164. }
  165. break;
  166. }
  167. return $ret;
  168. }
  169. /**
  170. * Merge the contents of two objects/array.
  171. *
  172. * array V::extend(mixed $defaults, mixed $params);
  173. * @see http://api.jquery.com/jQuery.extend/
  174. * is_scalar($from) - return TRUE if int,float,string,bool, FALSE if array,object,resource, ...
  175. */
  176. public static function extend($defaults, $params) {
  177. $ret = array();
  178. $d = (is_array($defaults))? $defaults : (array)$defaults;
  179. $p = (is_array($params))? $params : (array)$params;
  180. foreach ($d as $k => $v) {
  181. $ret[$k] = $v;
  182. }
  183. foreach ($p as $k => $v) {
  184. if (array_key_exists($k, $ret) && (is_array($ret[$k]) || is_object($ret[$k])) && (is_array($v) || is_object($v))) {
  185. $ret[$k] = V::extend($ret[$k], $v);
  186. } else {
  187. $ret[$k] = $v;
  188. }
  189. }
  190. return $ret;
  191. }
  192. public static function json_encode_latin2($o, $force_object = false) {
  193. if ($o === '') {
  194. return '""';
  195. }
  196. else if (!$o) {
  197. return 'null';
  198. }
  199. else if (is_array($o)) {
  200. $arr = '';
  201. if ($force_object) {
  202. foreach ($o as $k => $v) {
  203. $arr[] = '"'.$k.'":'.V::json_encode_latin2($v, $force_object);
  204. }
  205. return '{'.implode(',',$arr).'}';
  206. }
  207. else {
  208. foreach ($o as $k => $v) {
  209. if (is_string($k)) $arr[] = '"'.$k.'":'.V::json_encode_latin2($v, $force_object);
  210. else $arr[] = V::json_encode_latin2($v);
  211. }
  212. return '['.implode(',',$arr).']';
  213. }
  214. }
  215. else if (is_object($o)) {
  216. $arr = '';
  217. foreach (get_object_vars($o) as $k => $v) {
  218. $arr[] = '"'.$k.'":'.V::json_encode_latin2($v, $force_object);
  219. }
  220. return '{'.implode(',',$arr).'}';
  221. }
  222. else if (is_string($o)) {
  223. return '"'.addslashes(str_replace(array("\n","\r"), array('\n',''), $o)).'"';
  224. }
  225. else if (is_numeric($o)) {
  226. return ''.$o.'';
  227. }
  228. else if (is_bool($o)) {
  229. return ''.(($o)? 'true' : 'false').'';
  230. }
  231. }
  232. public static function copy($o) {
  233. $null = null;
  234. if (!$o) {
  235. return $null;
  236. }
  237. else if (is_array($o)) {
  238. $ret = array();
  239. foreach ($o as $k => $v) {
  240. $ret[$k] = $v;
  241. }
  242. return $ret;
  243. }
  244. else if (is_object($o)) {
  245. $ret = new stdClass();
  246. foreach (get_object_vars($o) as $k => $v) {
  247. $ret->$k = $v;
  248. }
  249. return $ret;
  250. }
  251. else {
  252. $ret = $o;
  253. return $ret;
  254. }
  255. }
  256. public static function make_link($prefix = '', $params = array()) {
  257. $ret = '';
  258. if ($prefix) {
  259. $ret = $prefix;
  260. }
  261. if (!empty($params)) {
  262. $ret_arr = array();
  263. foreach ($params as $k => $v) {
  264. $ret_arr[] = $k . "=" . $v;
  265. }
  266. $ret .= "?" . implode("&", $ret_arr);
  267. }
  268. return $ret;
  269. }
  270. public static function strShort($label, $maxLength = 10, $suffix = ' ...') {
  271. if (strlen($label) > $maxLength) {
  272. $pos = strpos($label, ' - ');
  273. if ($pos > $maxLength || $pos < 5) {
  274. $label = substr($label, 0, $pos) . $suffix;
  275. } else {
  276. $label = substr($label, 0, $pos);
  277. }
  278. }
  279. return $label;
  280. }
  281. public static function strShortUtf8($label, $maxLength = 10, $suffix = ' ...') {
  282. if (mb_strlen($label, 'utf-8') > $maxLength) {
  283. $pos = mb_strpos($label, ' - ', 0, 'utf-8');
  284. if ($pos > $maxLength || $pos < 5) {
  285. $label = mb_substr($label, 0, $maxLength, 'utf-8') . $suffix;
  286. } else {
  287. $label = mb_substr($label, 0, $pos, 'utf-8');
  288. }
  289. }
  290. return $label;
  291. }
  292. public static function filter($array, $filterCallback) {
  293. if (!is_callable($filterCallback)) {
  294. throw new Exception("callback is not callable '" . ((is_array($filterCallback))? implode('.', $filterCallback) : $filterCallback) . "'");
  295. }
  296. return array_filter($array, $filterCallback);
  297. }
  298. public static function filterNotEmpty($value) {
  299. return !empty($value);
  300. }
  301. public static function filterInteger($value) {// An integer or string with integer value
  302. if (is_int($value)) {
  303. return true;
  304. } else if (is_string($value)) {
  305. if ((string)(int)$value === $value) {
  306. return true;
  307. }
  308. }
  309. return false;
  310. }
  311. public static function filterNegativeInteger($value) {// An integer containing only negative values (..,-2,-1)
  312. if (V::filterInteger($value)) {
  313. if (intval($value) < 0) {
  314. return true;
  315. }
  316. }
  317. return false;
  318. }
  319. public static function filterNonNegativeInteger($value) {// An integer containing only non-negative values (0,1,2,..)
  320. if (V::filterInteger($value)) {
  321. if (intval($value) >= 0) {
  322. return true;
  323. }
  324. }
  325. return false;
  326. }
  327. public static function filterNonPositiveInteger($value) {// An integer containing only non-positive values (..,-2,-1,0)
  328. if (V::filterInteger($value)) {
  329. if (intval($value) <= 0) {
  330. return true;
  331. }
  332. }
  333. return false;
  334. }
  335. public static function filterPositiveInteger($value) {// An integer containing only positive values (1,2,..)
  336. if (V::filterInteger($value)) {
  337. if (intval($value) > 0) {
  338. return true;
  339. }
  340. }
  341. return false;
  342. }
  343. public static function validate($argName, $args, $params) {
  344. //$what = V::validate('what', $args, array('type'=>'word', 'not_empty'=>true, 'max_length'=>'255', 'values'=>$when_values));
  345. $argValue = V::get($argName, null, $args);
  346. $fldLabel = V::get('fld_label', $argName, $params);
  347. if (array_key_exists('not_empty', $params) && true == $params['not_empty']) {
  348. if (!array_key_exists($argName, $args) || empty($args[$argName])) throw new Exception("Field {$fldLabel} not set.");
  349. }
  350. $params['fld_label'] = $fldLabel;
  351. return V::validateValue($argValue, $params);
  352. }
  353. public static function validateValue($value, $params) {
  354. $fldLabel = V::get('fld_label', '', $params);
  355. $maxLength = V::get('max_length', 0, $params);
  356. if ($maxLength > 0) {
  357. if (strlen($value) > $maxLength) throw new Exception("'{$fldLabel}' cannot be longer then {$maxLength}.");
  358. }
  359. $allowedValues = V::get('values', null, $params);
  360. if (is_array($allowedValues) && !empty($allowedValues)) {
  361. if (!in_array($value, $allowedValues)) throw new Exception("'{$fldLabel}' value is not allowed");
  362. }
  363. $type = V::get('type', null, $params);
  364. if ($type != null) {
  365. if ('word' == $type) {
  366. if (!is_scalar($value) || !preg_match('/^[a-zA-Z_-]*$/', $value)) throw new Exception("required type '{$type}' ({$fldLabel})");
  367. } else {
  368. throw new Exception("Unimplemented type to validate: '{$type}'");
  369. }
  370. }
  371. if (array_key_exists('equal', $params)) {
  372. if ($value != $params['equal']) throw new Exception(V::get('error_msg_equal', "'{$fldLabel}' must be equal to '{$params['equal']}'", $params));
  373. }
  374. if (array_key_exists('equalStrict', $params)) {
  375. if ($value !== $params['equalStrict']) throw new Exception(V::get('error_msg_equalStrict', "'{$fldLabel}' must be strict equal to '{$params['equal']}'", $params));
  376. }
  377. return $value;
  378. }
  379. public static function exec($cmd, &$out, &$ret) {
  380. $out = null;
  381. $ret = null;
  382. $path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/lib/mysql55/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/Users/pl/programy/bin";
  383. $cmd = "{$path}\n{$cmd}";
  384. exec($cmd, $out, $ret);
  385. return $ret;
  386. }
  387. public static function execRemote($host, $login, $password, $command, &$out, &$ret, $port = 22) {
  388. $out = null;
  389. $ret = null;
  390. $pass = $password;
  391. $pass = str_replace('!', '\!', $pass);
  392. $sshPort = (22 != $port)? "-p {$port}" : '';
  393. $cmd = '/opt/local/bin/sshpass -p ' . $pass . ' ssh -o StrictHostKeyChecking=no -o ConnectTimeout=99999 ' . $sshPort . ' ' . $login . '@' . $host . ' -t <<EOF
  394. declare PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/lib/mysql55/bin/:/Applications/Server.app/Contents/ServerRoot/usr/sbin/
  395. '.$command.'
  396. EOF';
  397. exec($cmd, $out, $ret);
  398. return $ret;
  399. }
  400. public static function execRootRemote($host, $login, $password, $command, &$out, &$ret, $port = 22) {
  401. $out = null;
  402. $ret = null;
  403. $pass = $password;
  404. $pass = str_replace('!', '\!', $pass);
  405. $sshPort = (22 != $port)? "-p {$port}" : '';
  406. $cmd = '/opt/local/bin/sshpass -p ' . $pass . ' ssh -o StrictHostKeyChecking=no -o ConnectTimeout=99999 ' . $sshPort . ' ' . $login . '@' . $host . ' -t <<EOF
  407. sudo -n su -
  408. declare PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/lib/mysql55/bin/:/Applications/Server.app/Contents/ServerRoot/usr/sbin/
  409. '.$command.'
  410. EOF';
  411. exec($cmd, $out, $ret);
  412. return $ret;
  413. }
  414. public static function cloneArray($arr) {
  415. return $arr;
  416. }
  417. public static function humanFileSize($bytes) {
  418. $bytes = intval($bytes);
  419. $arBytes = array(
  420. 0 => array("UNIT" => "TB", "VALUE" => pow(1024, 4)),
  421. 1 => array("UNIT" => "GB", "VALUE" => pow(1024, 3)),
  422. 2 => array("UNIT" => "MB", "VALUE" => pow(1024, 2)),
  423. 3 => array("UNIT" => "KB", "VALUE" => 1024),
  424. 4 => array("UNIT" => "B", "VALUE" => 1)
  425. );
  426. foreach($arBytes as $arItem) {
  427. if ($bytes >= $arItem["VALUE"]) {
  428. $result = $bytes / $arItem["VALUE"];
  429. $result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"];
  430. break;
  431. }
  432. }
  433. return $result;
  434. }
  435. public static function kwotaSlownie($kwota = 0, $waluta = "PLN") {
  436. if (!preg_match("/^[[:digit:]]*(\.[[:digit:]]+)?$/",$kwota)) throw new Exception("Błędna liczba");
  437. if (!preg_match("/^[[:digit:]]{0,48}(\.[[:digit:]]+)?$/",$kwota)) throw new Exception("Zbyt duża liczba");
  438. $waluty = array(
  439. 'PLN' => array('złoty','złotych','złote'),
  440. 'USD' => array('dolar','dolarów','dolary')
  441. );
  442. $jednosci = array('zero','jeden','dwa','trzy','cztery','pięć','sześć','siedem','osiem','dziewięć','dziesięć','jedenaście',
  443. 'dwanaście','trzynaście','czternaście','piętnaście','szesnaście','siednaście','osiemnaście','dziewiętnaście');
  444. $dziesiatki = array('','','dwadzieścia','trzydzieści','czterdzieści','pięćdziesiąt','sześćdziesiąt','siedemdziesiąt','osiemdziesiąt','dziewięćdziesiąt');
  445. $setki = array('','sto','dwieście','trzysta','czterysta','pięćset','sześćset','siedemset','osiemset','dziewięćset');
  446. if (!isset($waluty[$waluta])) $tysiace[] = array($waluta,$waluta,$waluta);
  447. else $tysiace[] = $waluty[$waluta];
  448. $tysiace[] = array('tysiąc','tysięcy','tysiące');
  449. $tysiace[] = array('milion','milionów','miliony');
  450. $tysiace[] = array('miliard','miliardów','miliardy');
  451. $tysiace[] = array('bilion','bilionów','bilony');
  452. $tysiace[] = array('biliard','biliardów','biliardy');
  453. $tysiace[] = array('trylion','trylionów','tryliony');
  454. $tysiace[] = array('tryliard','tryliardów','tryliardy');
  455. $tysiace[] = array('kwadrylion','kwadrylionów','kwadryliony');
  456. $tysiace[] = array('kwadryliard','kwadryliardów','kwaryliardy');
  457. $tysiace[] = array('kwintylion','kwintylionów','kwintyliony');
  458. $tysiace[] = array('kwintyliard','kwintyliardów','kwintyliardy');
  459. $tysiace[] = array('sekstylion','sekstylionów','sepstyliony');
  460. $tysiace[] = array('sekstyliard','sekstyliardów','sekstyliardy');
  461. $tysiace[] = array('septylion','septylionów','septyliony');
  462. $tysiace[] = array('septyliard','septyliardów','septyliardy');
  463. $kwota = (!substr_count($kwota, '.')) ? $kwota.'.00' : $kwota;
  464. list($zlote, $grosze) = explode('.', $kwota);
  465. $zlote = ltrim($zlote, '0');
  466. if ($zlote == '') $zlote = '0';
  467. if (strlen($grosze) == 1) $grosze .= "0";
  468. elseif (strlen($grosze) > 2) $grosze = round(substr($grosze, 0, 2).".".substr($grosze, 2), 0);
  469. $zlote = strrev(wordwrap(strrev($zlote), 3, '.', true));
  470. $zloteArr = explode('.', $zlote);
  471. foreach ($zloteArr as $i => $l) {
  472. $tysiac = count($zloteArr) - $i - 1;
  473. $setka = $setki[floor($l/100)];
  474. $dziesiatka = $dziesiatki[floor(($l%100)/10)];
  475. $jednosc = $dziesiatka ? $jednosci[$l%10] : $jednosci[$l%100];
  476. if ($l == 1 and ($tysiac > 0 or count($zloteArr) == 1)) $odmiana = 0;
  477. elseif (floor($l%100/10) != 1 and $l%10 >= 2 and $l%10 <= 4) $odmiana = 2;
  478. else $odmiana = 1;
  479. if ($setka) $resultArr[] = $setka;
  480. if ($dziesiatka) $resultArr[] = $dziesiatka;
  481. if ($jednosc == $jednosci[0] && $zlote != '0') $jednosc = '';
  482. if ($jednosc) $resultArr[] = $jednosc;
  483. if ($setka || $dziesiatka || $jednosc || $tysiac == 0) $resultArr[] = $tysiace[$tysiac][$odmiana];
  484. }
  485. $resultArr[] = $grosze . "/100";
  486. return implode(" ", $resultArr);
  487. }
  488. public static function nettoOdBrutto($brutto = 0, $vat = "23") {
  489. if ($vat < 0) throw new Exception("Stawka VAT nie może być liczbą ujemną!");
  490. $netto = round($brutto/(1+$vat/100),2);
  491. if (round($netto*(1+$vat/100),2) > $brutto) $netto -= 0.01;
  492. return $netto;
  493. }
  494. public static function pickSimgleValue($items, $fieldName) {
  495. return array_map(
  496. function ($row) use ($fieldName) {
  497. return V::get($fieldName, '', $row);
  498. }
  499. , $items
  500. );
  501. }
  502. public static function pickArrayValues($items, $fieldNames) {
  503. return $items;
  504. }
  505. public static function arrayToXML($array, $formatOutput = false, $root = "root") {
  506. function arrayToXML_rec($data, $dom, $node, $parent = null) {
  507. $child = $dom->createElement($node);
  508. if (!$parent) $parent = $dom;
  509. if (is_array($data)) {
  510. foreach ($data as $key => $value) {
  511. if (is_numeric($key)) arrayToXML_rec($value, $dom, $node, $parent);
  512. else arrayToXML_rec($value, $dom, $key, $child);
  513. }
  514. } else {
  515. if ($data) {
  516. if ($data == htmlspecialchars($data)) $child->nodeValue = $data;
  517. else $child->appendChild($dom->createCDATASection($data));
  518. } else $parent->appendChild($child);
  519. }
  520. if ($child->hasChildNodes()) $parent->appendChild($child);
  521. }
  522. if (!is_array($array)) throw new Exception("First argument need to be an array");
  523. $dom = new DOMDocument('1.0', 'UTF-8');
  524. $dom->preserveWhiteSpace = false;
  525. $dom->formatOutput = $formatOutput;
  526. arrayToXML_rec($array, $dom, $root);
  527. return $dom->saveXML();
  528. }
  529. }