3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $fName = "item.txt"; // 1 $fp = fopen($fName, "r") or die("File not found/opened!"); // 2 $lineCount = 0; while ($lineIn = fgets($fp) ) { // 3 print("$lineIn <br/>"); $lineCount++; } print ("line count = $lineCount<br/><br/>"); fclose($fp); $fp = fopen($fName, "r"); // 4 $lineIn = fgets($fp); $id = substr($lineIn, 0, 5); $name = substr($lineIn, 6, 14); $cost = substr($lineIn, 21, 6); $qty = substr($lineIn, 28, 1); print("<pre>"); print("$id\t$name\t$cost\t$qty\n\n"); fclose($fp); $fName = "item.csv"; $fp = fopen($fName, "r") or die("File not found/opened!"); $delimiter = ','; $totalCost = 0.00; print("<font face = \"Lucida Console\" size = \"3\" >"); printf("%30s", "Item Inventory\n"); printf("%5s \t %-14s \t %6s \t %-3s\n", "id", "name", "cost", "qty"); while ($item = fgetcsv($fp, $delimiter) ) { // 5 $id = $item[0]; $name = $item[1]; $cost = $item[2]; $qty = $item[3]; printf("%5d \t %-14s \t %6.2f \t %1d\n", $id, $name, $cost, $qty); $totalCost += $cost; } printf("%31s %7.2f", "total cost:", $totalCost); fclose($fp); ?>
Output for 4.3.2 - 5.6.28, 7.0.0 - 7.1.0
Warning: fopen(item.txt): failed to open stream: No such file or directory in /in/eGWD1 on line 3 File not found/opened!
Output for hhvm-3.10.0 - 3.12.0
Warning: No such file or directory in /in/eGWD1 on line 3 File not found/opened!
Output for 4.3.0 - 4.3.1
Warning: fopen(item.txt) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/eGWD1 on line 3 File not found/opened!