xml - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of xml.php

  1. <?php
  2. $str ='<Events>
  3. <Event>
  4.     <Name>Movie One</Name>
  5.     <Times>
  6.         <EventTime>
  7.         <Time>2019-02-10T14:30:00</Time>
  8.         <Capacity>100</Capacity>
  9.         </EventTime>
  10.     </Times> 
  11. </Event>
  12. <Event>
  13.     <Name>Movie One</Name>
  14.     <Times>
  15.         <EventTime>
  16.         <Time>2019-02-11T18:30:00</Time>
  17.         <Capacity>100</Capacity>
  18.         </EventTime>
  19.     </Times> 
  20. </Event>
  21. <Event>
  22.     <Name>Movie One</Name>
  23.     <Times>
  24.         <EventTime>
  25.         <Time>2019-02-12T18:30:00</Time>
  26.         <Capacity>100</Capacity>
  27.         </EventTime>
  28.     </Times> 
  29. </Event>
  30. </Events>';
  31.  
  32. $xml=simplexml_load_string($str) or die("Error: Not Working");
  33. foreach($xml->children() as $cinemalist) {
  34.     echo '<p>Event Name: ' . $cinemalist->Name . " </p> ";
  35.     foreach($cinemalist->children() as $alltimes) {
  36.         $showtimes = $alltimes->EventTime->Time;
  37.         echo '<span>' . $showtimes . " </span> ";  
  38.     }
  39. }
File Description
  • xml
  • PHP Code
  • 10 Feb-2019
  • 915 Bytes
You can Share it: