"PHP" / Говнокод #874 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
function arr2xml($data, $rootNodeName = 'response', $xml = null) {

                    if ($xml == null) {
                              $xml = simplexml_load_string("<$rootNodeName />");
                    }

                    // loop through the data passed in.
                    foreach($data as $key => $value) {
            // no numeric keys in our xml please!
            if (is_numeric($key)) {
                // make string key...
                $key = "unknownNode_". (string) $key;
            }

            // replace anything not alpha numeric
            $key = preg_replace('/[^a-z_0-9]/i', '', $key);

            // if there is another array found recrusively call this function
            if (is_array($value)) {
                $node = $xml->addChild($key);
                // recrusive call.
                arr2xml($value, $rootNodeName, $node);
            } else {
                // add single node.
                $value = $value;
                $xml->addChild($key,$value);
            }
        }

                    // pass back as string. or simple xml object if you want!
        $res = substr($xml->asXML(), 22);
        return $res;

    }

ХУЙПИЗДА ЗУМЛЬ

Запостил: guest guest, (Updated )

Комментарии (0) RSS

Добавить комментарий

Где здесь C++, guest?!

    А не использовать ли нам bbcode?


    8