3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlns_siri = 'http://www.siri.org.uk/siri'; $searchForID = '2755'; $reader = new XMLReader(); $reader->open('data:text/xml;base64,'.base64_encode(getXMLString())); $document = new DOMDocument(); $xpath = new DOMXpath($document); // register an alias for the siri namespace $xpath->registerNamespace('siri', $xmlns_siri); // look for the first "item" element node while ( $reader->read() && ( $reader->localName !== 'EstimatedVehicleJourney' || $reader->namespaceURI !== $xmlns_siri ) ) { continue; } // iterate "item" sibling elements while ($reader->localName === 'EstimatedVehicleJourney') { // validate the namespace of the node if ($reader->namespaceURI === $xmlns_siri) { // expand into DOM $item = $reader->expand($document); // if the node has a child "VehicleRef" with the searched contents // note the use of the registered namespace alias if ($xpath->evaluate("count(self::*[siri:VehicleRef = '$searchForID']) > 0", $item)) { var_dump( [ // fetch node text content as string 'name' => $xpath->evaluate('string(siri:OriginName)', $item), // fetch list of "call" elements and map them 'calls' => array_map( function(DOMElement $call) use ($xpath) { return [ 'name' => $xpath->evaluate('string(siri:StopPointName)', $call), 'reference' => $xpath->evaluate('string(siri:StopPointRef)', $call) ]; }, iterator_to_array( $xpath->evaluate('siri:RecordedCalls/siri:RecordedCall', $item) ) ) ] ); } } $reader->next('EstimatedVehicleJourney'); } $reader->close(); function getXMLString() { return <<<'XML' <Siri xmlns="http://www.siri.org.uk/siri"> <ServiceDelivery> <ResponseTimestamp>2021-09-02T18:36:10+02:00</ResponseTimestamp> <Status>true</Status> <MoreData>false</MoreData> <EstimatedTimetableDelivery> <ResponseTimestamp>2021-09-02T18:36:10+02:00</ResponseTimestamp> <ValidUntil>2021-09-02T19:36:10+02:00</ValidUntil> <EstimatedJourneyVersionFrame> <RecordedAtTime>2021-09-02T18:36:10+02:00</RecordedAtTime> <EstimatedVehicleJourney> <LineRef>L2</LineRef> <DirectionRef>SKI</DirectionRef> <DatedVehicleJourneyRef>2755:2021-09-02</DatedVehicleJourneyRef> <VehicleMode>rail</VehicleMode> <OriginRef>STB</OriginRef> <OriginName>Stabekk</OriginName> <DestinationRef>SKI</DestinationRef> <DestinationName>Ski</DestinationName> <OperatorRef>VY</OperatorRef> <ProductCategoryRef>Lt</ProductCategoryRef> <ServiceFeatureRef>passengerTrain</ServiceFeatureRef> <VehicleRef>2755</VehicleRef> <RecordedCalls> <RecordedCall> <StopPointRef>STB</StopPointRef> <StopPointName>Stabekk</StopPointName> <AimedDepartureTime>2021-09-02T18:19:00+02:00</AimedDepartureTime> <DeparturePlatformName>2</DeparturePlatformName> <ActualDepartureTime>2021-09-02T18:19:13+02:00</ActualDepartureTime> </RecordedCall> <RecordedCall> <StopPointRef>STB</StopPointRef> <StopPointName>Stabekk</StopPointName> <AimedDepartureTime>2021-09-02T18:19:00+02:00</AimedDepartureTime> <DeparturePlatformName>2</DeparturePlatformName> <ActualDepartureTime>2021-09-02T18:19:13+02:00</ActualDepartureTime> </RecordedCall> </RecordedCalls> <EstimatedCalls> <EstimatedCall> <StopPointRef>SKI</StopPointRef> <StopPointName>Ski</StopPointName> <RequestStop>false</RequestStop> <AimedArrivalTime>2021-09-02T18:39:00+02:00</AimedArrivalTime> <ExpectedArrivalTime>2021-09-02T18:40:42+02:00</ExpectedArrivalTime> <ArrivalStatus>onTime</ArrivalStatus> <ArrivalPlatformName>1</ArrivalPlatformName> <ArrivalBoardingActivity>alighting</ArrivalBoardingActivity> </EstimatedCall> <EstimatedCall> <StopPointRef>SKI</StopPointRef> <StopPointName>Ski</StopPointName> <RequestStop>false</RequestStop> <AimedArrivalTime>2021-09-02T18:39:00+02:00</AimedArrivalTime> <ExpectedArrivalTime>2021-09-02T18:40:42+02:00</ExpectedArrivalTime> <ArrivalStatus>onTime</ArrivalStatus> <ArrivalPlatformName>1</ArrivalPlatformName> <ArrivalBoardingActivity>alighting</ArrivalBoardingActivity> </EstimatedCall> </EstimatedCalls> <IsCompleteStopSequence>true</IsCompleteStopSequence> </EstimatedVehicleJourney> <EstimatedVehicleJourney> <LineRef>L2</LineRef> <DirectionRef>SKI</DirectionRef> <DatedVehicleJourneyRef>2755:2021-09-02</DatedVehicleJourneyRef> <VehicleMode>rail</VehicleMode> <OriginRef>STB</OriginRef> <OriginName>Stabekk</OriginName> <DestinationRef>SKI</DestinationRef> <DestinationName>Ski</DestinationName> <OperatorRef>VY</OperatorRef> <ProductCategoryRef>Lt</ProductCategoryRef> <ServiceFeatureRef>passengerTrain</ServiceFeatureRef> <VehicleRef>2755</VehicleRef> <RecordedCalls> <RecordedCall> <StopPointRef>STB</StopPointRef> <StopPointName>Stabekk</StopPointName> <AimedDepartureTime>2021-09-02T18:19:00+02:00</AimedDepartureTime> <DeparturePlatformName>2</DeparturePlatformName> <ActualDepartureTime>2021-09-02T18:19:13+02:00</ActualDepartureTime> </RecordedCall> <RecordedCall> <StopPointRef>STB</StopPointRef> <StopPointName>Stabekk</StopPointName> <AimedDepartureTime>2021-09-02T18:19:00+02:00</AimedDepartureTime> <DeparturePlatformName>2</DeparturePlatformName> <ActualDepartureTime>2021-09-02T18:19:13+02:00</ActualDepartureTime> </RecordedCall> </RecordedCalls> <EstimatedCalls> <EstimatedCall> <StopPointRef>SKI</StopPointRef> <StopPointName>Ski</StopPointName> <RequestStop>false</RequestStop> <AimedArrivalTime>2021-09-02T18:39:00+02:00</AimedArrivalTime> <ExpectedArrivalTime>2021-09-02T18:40:42+02:00</ExpectedArrivalTime> <ArrivalStatus>onTime</ArrivalStatus> <ArrivalPlatformName>1</ArrivalPlatformName> <ArrivalBoardingActivity>alighting</ArrivalBoardingActivity> </EstimatedCall> <EstimatedCall> <StopPointRef>SKI</StopPointRef> <StopPointName>Ski</StopPointName> <RequestStop>false</RequestStop> <AimedArrivalTime>2021-09-02T18:39:00+02:00</AimedArrivalTime> <ExpectedArrivalTime>2021-09-02T18:40:42+02:00</ExpectedArrivalTime> <ArrivalStatus>onTime</ArrivalStatus> <ArrivalPlatformName>1</ArrivalPlatformName> <ArrivalBoardingActivity>alighting</ArrivalBoardingActivity> </EstimatedCall> </EstimatedCalls> <IsCompleteStopSequence>true</IsCompleteStopSequence> </EstimatedVehicleJourney> </EstimatedJourneyVersionFrame> </EstimatedTimetableDelivery> </ServiceDelivery> </Siri> XML; }
Output for 8.0.10, 8.1.23 - 8.1.33, 8.2.10 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.27, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
array(2) { ["name"]=> string(7) "Stabekk" ["calls"]=> array(2) { [0]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } [1]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } } } array(2) { ["name"]=> string(7) "Stabekk" ["calls"]=> array(2) { [0]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } [1]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } } }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(2) { ["name"]=> string(7) "Stabekk" ["calls"]=> array(2) { [0]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } [1]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } } } array(2) { ["name"]=> string(7) "Stabekk" ["calls"]=> array(2) { [0]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } [1]=> array(2) { ["name"]=> string(7) "Stabekk" ["reference"]=> string(3) "STB" } } }

preferences:
116.24 ms | 411 KiB | 5 Q