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 git.master, git.master_jit, rfc.property-hooks
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!

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.66 ms | 402 KiB | 8 Q