Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [simpleXML] funkcja obj2array zle dziala
aleksander
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 742
Pomógł: 0
Dołączył: 14.12.2003
Skąd: Gdańsk, Trójmiasto

Ostrzeżenie: (0%)
-----


witam,

Na php.net znalazłem funkcję która konwertuje obiekt simplexml do tablicy:
  1. <?php
  2. function recursive_obj2array( $obj )
  3. {
  4. $subject_array = array();
  5.  foreach ((array) $obj as $key => $var)
  6.  {
  7.  if (is_object($var))
  8.  {
  9.  if(count((array) $var) == 0)
  10.  {
  11.  $subject_array[$key] = 'NULL';
  12. }
  13. else
  14. {
  15. recursive_obj2array($var );
  16. }
  17. }
  18. else
  19. {
  20. $subject_array[$key] = $var;
  21. }
  22. }
  23. return $subject_array;
  24. }
  25.  
  26. echo '<pre>';
  27. print_r( recursive_obj2array( simplexml_load_file('xml.xml') ) );
  28. echo '</pre>'; 
  29. ?>
Niestety dla takiego xmlu:
  1. <actions>
  2.    <action>
  3.      <default>true</default>
  4.      <name>main</name>
  5.      <requiredRoles>viewNews</requiredRoles>
  6.      <type>view</type>
  7.      <matches>main</matches>
  8.      <fallback>accessDenied</fallback>
  9.    </action>
  10.  
  11.    <action>
  12.      <name>footer</name>
  13.      <requiredRoles>viewNews</requiredRoles>
  14.      <type>view</type>
  15.      <matches>null</matches>
  16.      <fallback>accessDenied</fallback>
  17.    </action>
  18. </actions>
wychodzi zly kod, bo z obiektem:
Cytat
Array
(
    [action] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [default] => true
                    [name] => main
                    [requiredRoles] => viewNews
                    [type] => view
                    [matches] => main
                    [fallback] => accessDenied
                )

            [1] => SimpleXMLElement Object
                (
                    [name] => footer
                    [requiredRoles] => viewNews
                    [type] => view
                    [matches] => null
                    [fallback] => accessDenied
                )

        )

)
Nie wiem jak to naprawić, bo zamiast obiektu powinna byc kolejna tablica (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) Może mi ktoś pomóc?

Ten post edytował olo 13.01.2005, 18:03:26
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 00:01