3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php header("Content-type: text/plain"); //period=68 for month, period=67 for weekly, period=56 for daily, only for html $stock="2888"; $arrCSV = array(); $url = "http://chartdata1.internet.aastocks.com/servlet/iDataServlet/getdaily?id=".$stock.".HK&type=24&market=1&level=1&period=56&encoding=big5"; $html = file_get_contents($url); $c = str_replace("|","\r\n",$html); $d = str_replace(";",",",$c); $pos = substr_count($d,'!'); if ($pos == 1){ $file = strstr($d,'!',true); }else{ $file = str_replace("!","\r\n",$d); } { $key = 1; $row = str_getcsv($file, "\n"); $length = count($row); for($i=2;$i<$length;$i++) { $data = str_getcsv($row[$i], ","); //echo '<br/>======<br/>'; //print_r($data); $c = count($data); //print $c . "<BR>"; // <------ 7 o numero de colunas //Populate the array If ($key != 0) { $arrCSV[$key-1][0] = strtotime($data[0]); //Time $arrCSV[$key-1][1] = $data[1]; //Open $arrCSV[$key-1][2] = $data[2]; //High $arrCSV[$key-1][3] = $data[3]; //Low $arrCSV[$key-1][4] = $data[4]; //Adj Close $arrCSV[$key-1][5] = $data[5]*1000; //Volume $arrCSV[$key-1][6] = $data[6]; //Volume1 } $key++; } // end while $keymax = $key; // Close the CSV file } // end if $key = 1; rsort ($arrCSV); foreach($arrCSV as $index => $data) { //echo '<br/>======<br/>'; //print_r($data); $c = count($data); //print $c . "<BR>"; // <------ 6 numero de colunas If ($key != 0) { $arrCSV[$key-1][0] = date('d-m-Y',$data[0]); //Time $arrCSV[$key-1][1] = floatval($data[1]); //Open $arrCSV[$key-1][2] = floatval($data[2]); //High $arrCSV[$key-1][3] = floatval($data[3]); //Low $arrCSV[$key-1][4] = floatval($data[4]); //Close $arrCSV[$key-1][5] = floatval($data[5]); //Volume $arrCSV[$key-1][6] = floatval($data[6]); //Volume1 } //echo '<Br/>'; //print_r($arrCSV[$key-1]); $key++; } // end while $keymax = $key; $a = json_encode($arrCSV,JSON_NUMERIC_CHECK); $b = str_replace('],["',"\r\n",$a); $c = str_replace('",',',',$b); $file = trim($c,'[["]]'); echo "<html><body><table>\n\n"; $row = str_getcsv($file, "\n"); $length = count($row); for($i=0;$i<$length;$i++) { $line = str_getcsv($row[$i], ","); foreach ($line as $cell) { echo "<td>" . htmlspecialchars($cell) . "</td>"; } echo "</tr>\n"; } echo "\n</table></body></html>"; header("Content-type: application/html"); header("Content-disposition: attachment; filename=".$stock."_AA.html"); ?>
Output for 7.0.20, 7.1.5 - 7.3.0beta1
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/0LC2u on line 7 Warning: file_get_contents(http://chartdata1.internet.aastocks.com/servlet/iDataServlet/getdaily?id=2888.HK&type=24&market=1&level=1&period=56&encoding=big5): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/0LC2u on line 7 <html><body><table> <td></td></tr> </table></body></html> Warning: Cannot modify header information - headers already sent by (output started at /in/0LC2u:7) in /in/0LC2u on line 96 Warning: Cannot modify header information - headers already sent by (output started at /in/0LC2u:7) in /in/0LC2u on line 97
Output for 5.5.0 - 7.0.10, 7.1.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/0LC2u on line 7 Warning: file_get_contents(http://chartdata1.internet.aastocks.com/servlet/iDataServlet/getdaily?id=2888.HK&type=24&market=1&level=1&period=56&encoding=big5): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/0LC2u on line 7 <html><body><table> <td></td></tr> </table></body></html> Warning: Cannot modify header information - headers already sent by (output started at /in/0LC2u:7) in /in/0LC2u on line 96 Warning: Cannot modify header information - headers already sent by (output started at /in/0LC2u:7) in /in/0LC2u on line 97