Advertisement
froddo

Untitled

Dec 11th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <?php
  2. $xml=simplexml_load_file("demo_xml.xml") or die("Error: Cannot create object"); // get object
  3.  
  4. //echo '<pre>';
  5. //print_r($xml);
  6. //echo '</pre>';
  7. $path = "demo_xml.xml";
  8. $file_get = file_get_contents($path);
  9. $load = simplexml_load_string($file_get);
  10. $get_json = json_encode($load);
  11. $result = json_decode($get_json, true);
  12.  
  13. //
  14. //foreach ($result as $item) {
  15. //
  16. //    foreach ($item as $value) {
  17. //
  18. //        foreach ($value as $items) {
  19. //
  20. //            foreach ($items as $get_item) {
  21. //                echo '<pre>';
  22. //                print_r($get_item[0]);
  23. //                echo '</pre>';
  24. //            }
  25. //
  26. //        }
  27. //
  28. //
  29. //    }
  30. //
  31. //}
  32.  
  33. //$servername = "localhost";
  34. //$username = "frodo";
  35. //$password = "qwerty";
  36. //$dbname = "xml_db";
  37. //
  38. //
  39. //$conn = new mysqli($servername, $username, $password, $dbname);
  40. //
  41. //if ($conn->connect_error) {
  42. //    die("Connection failed: " . $conn->connect_error);
  43. //}
  44. //
  45. //
  46. //$sql = "CREATE TABLE xml (
  47. //room_id  INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  48. //hotel_caption VARCHAR(30) NOT NULL,
  49. //room_caption VARCHAR(30) NOT NULL,
  50. //price DECIMAL (50),
  51. //)";
  52. //
  53. //if ($conn->query($sql) === TRUE) {
  54. //    echo "Ok";
  55. //} else {
  56. //    echo "Error" . $conn->error;
  57. //}
  58. //$conn->close();
  59.  
  60. foreach ($xml->children() as $item) {
  61.  
  62.     foreach ($item->children() as $value) {
  63.         foreach ($value->children() as $child) {
  64.            
  65.             echo $child->getName(). ": " . $child . "<br />";
  66.         }
  67.  
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement