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 git.master, git.master_jit, rfc.property-hooks
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" } } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
100.7 ms | 407 KiB | 5 Q