3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Warning: fopen(): open_basedir restriction in effect. File(item.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/eGWD1 on line 3 Warning: fopen(item.txt): Failed to open stream: Operation not permitted in /in/eGWD1 on line 3 File not found/opened!
Output for 8.0.13
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 4.3.2 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.3.32 - 7.3.33, 7.4.33
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 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
Warning: fopen(): open_basedir restriction in effect. File(item.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/eGWD1 on line 3 Warning: fopen(item.txt): failed to open stream: Operation not permitted 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!

preferences:
240 ms | 401 KiB | 351 Q