3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $a = <<< EOF <?xml version="1.0" encoding="ISO-8859-1" ?> <datainfo> <origin>NOAA/NOS/CO-OPS</origin> <disclaimer>Disclaimer: These data are based upon the latest information available as of the date of your request, and may differ from the published tide tables. </disclaimer> <producttype> Annual Tide Prediction </producttype> <stationname>Nonopapa, Niihau Island</stationname> <state>HI</state> <stationid>1610367</stationid> <stationtype>Subordinate</stationtype> <referencedToStationName>HONOLULU</referencedToStationName> <referencedToStationId>1612340</referencedToStationId> <HeightOffsetLow>*0.77</HeightOffsetLow> <HeightOffsetHigh>* 0.77</HeightOffsetHigh> <TimeOffsetLow>-11</TimeOffsetLow> <TimeOffsetHigh>-16</TimeOffsetHigh> <BeginDate>20131231 00:00</BeginDate> <EndDate>20141231 23:59</EndDate> <dataUnits>feet(ft) also in centimeters(cm)</dataUnits> <Timezone>LST</Timezone> <Datum>MLLW</Datum> <IntervalType>High/Low Tide Predictions</IntervalType> <data> <item> <date>2013/12/31</date> <day>Tue</day> <time>03:11 AM</time> <predictions_in_ft>2.0</predictions_in_ft> <predictions_in_cm>61</predictions_in_cm> <highlow>H</highlow> </item> <item> <date>2013/12/31</date> <day>Tue</day> <time>10:21 AM</time> <predictions_in_ft>0.1</predictions_in_ft> <predictions_in_cm>3</predictions_in_cm> <highlow>L</highlow> </item> </data></datainfo> EOF; $needToKeep = ['referencedToStationName','referencedToStationId','HeightOffsetLow','HeightOffsetHigh','TimeOffsetLow','TimeOffsetHigh','stationname','stationid','stationtype']; $b = simplexml_load_string($a); $json = json_encode($b ); $array = json_decode($json,true); // unset undesirables foreach($array as $k => $v){ if(!in_array($k, $needToKeep)) unset($array[$k]); }; var_export($array);
based on 6751U
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array ( 'stationname' => 'Nonopapa, Niihau Island', 'stationid' => '1610367', 'stationtype' => 'Subordinate', 'referencedToStationName' => 'HONOLULU', 'referencedToStationId' => '1612340', 'HeightOffsetLow' => '*0.77', 'HeightOffsetHigh' => '* 0.77', 'TimeOffsetLow' => '-11', 'TimeOffsetHigh' => '-16', )
Output for 4.4.3 - 4.4.9, 5.1.0 - 5.1.1, 5.1.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/WgXC7 on line 43
Process exited with code 255.
Output for 4.4.2, 5.1.2
Parse error: syntax error, unexpected '[' in /in/WgXC7 on line 44
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/WgXC7 on line 43
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/WgXC7 on line 43
Process exited with code 255.