3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data= '"CIEL3.SA",35.10,"SAO","+4.71%",+1.58,35.85,34.00,"34.00 - 35.85",8637900,"BRL","3/17/2016","5:08pm"'; $properties=explode(",",$data); $fields = array('Symbol', 'LastTradePriceOnly', 'StockExchange', 'ChangeinPercent', 'Change', 'DaysHigh', 'DaysLow', 'DaysRange', 'Volume', 'Currency', 'LastTradeDate', 'LastTradeTime'); foreach ($properties as $key=>$value) { $quotes[] = array ( $fields[$key] => $value ); }; $results = array ( "query" => array ( "results" => array ( "quote" => $quotes ) ) ); echo json_encode($results); $row = 1; $quotes = null; $stream = fopen('data://text/plain;base64,' . base64_encode($data),'r'); while (($data = fgetcsv($stream, 12, ",")) !== FALSE) { $num = count($data); echo "<p> $num campos na linha $row: <br /></p>\n"; $row++; foreach ($data as $key=>$value) { $quotes[] = array ( $fields[$key] => $value ); }; } $results = array ( "query" => array ( "results" => array ( "quote" => $quotes ) ) ); echo json_encode($results);
Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
{"query":{"results":{"quote":[{"Symbol":"\"CIEL3.SA\""},{"LastTradePriceOnly":"35.10"},{"StockExchange":"\"SAO\""},{"ChangeinPercent":"\"+4.71%\""},{"Change":"+1.58"},{"DaysHigh":"35.85"},{"DaysLow":"34.00"},{"DaysRange":"\"34.00 - 35.85\""},{"Volume":"8637900"},{"Currency":"\"BRL\""},{"LastTradeDate":"\"3\/17\/2016\""},{"LastTradeTime":"\"5:08pm\""}]}}}<p> 2 campos na linha 1: <br /></p> <p> 11 campos na linha 2: <br /></p> {"query":{"results":{"quote":[{"Symbol":"CIEL3.SA"},{"LastTradePriceOnly":"3"},{"Symbol":"5.10"},{"LastTradePriceOnly":"SAO"},{"StockExchange":"+4.71%"},{"ChangeinPercent":"+1.58"},{"Change":"35.85"},{"DaysHigh":"34.00"},{"DaysLow":"34.00 - 35.85"},{"DaysRange":"8637900"},{"Volume":"BRL"},{"Currency":"3\/17\/2016"},{"LastTradeDate":"5:08pm"}]}}}
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 {"query":{"results":{"quote":[{"Symbol":"\"CIEL3.SA\""},{"LastTradePriceOnly":"35.10"},{"StockExchange":"\"SAO\""},{"ChangeinPercent":"\"+4.71%\""},{"Change":"+1.58"},{"DaysHigh":"35.85"},{"DaysLow":"34.00"},{"DaysRange":"\"34.00 - 35.85\""},{"Volume":"8637900"},{"Currency":"\"BRL\""},{"LastTradeDate":"\"3\/17\/2016\""},{"LastTradeTime":"\"5:08pm\""}]}}}<p> 2 campos na linha 1: <br /></p> <p> 11 campos na linha 2: <br /></p> {"query":{"results":{"quote":[{"Symbol":"CIEL3.SA"},{"LastTradePriceOnly":"3"},{"Symbol":"5.10"},{"LastTradePriceOnly":"SAO"},{"StockExchange":"+4.71%"},{"ChangeinPercent":"+1.58"},{"Change":"35.85"},{"DaysHigh":"34.00"},{"DaysLow":"34.00 - 35.85"},{"DaysRange":"8637900"},{"Volume":"BRL"},{"Currency":"3\/17\/2016"},{"LastTradeDate":"5:08pm"}]}}}

preferences:
163.87 ms | 403 KiB | 248 Q