3v4l.org

run code in 300+ PHP versions simultaneously
<?php $handle = fopen('music_asdlist.txt', 'r'); $blocks = array(); $currentBlock = array(); while (!feof($handle)) { $line = fgets($handle); if (trim($line) == '') { if ($currentBlock) { $blocks[] = $currentBlock; $currentBlock = array(); } } else { $currentBlock[] = $line; } } fclose($handle); if ($currentBlock) { $blocks[] = $currentBlock; } function findTerm($term, $haystack) { $count = 0; foreach($haystack as $album) { if(in_array($term, $album)) { return $count; } } return false; } if(empty($blocks)) { echo "File import failed"; } else { $searchTerm = "strategy"; $album = findTerm($searhTerm, $blocks); if(isset($album)) { echo "Found term: <b>$searchTerm</b><br>"; echo "In album: ".$blocks[$album][2]; } } ?>
Output for git.master, git.master_jit
Warning: fopen(): open_basedir restriction in effect. File(music_asdlist.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/3h3uU on line 2 Warning: fopen(music_asdlist.txt): Failed to open stream: Operation not permitted in /in/3h3uU on line 2 Fatal error: Uncaught TypeError: feof(): Argument #1 ($stream) must be of type resource, bool given in /in/3h3uU:5 Stack trace: #0 /in/3h3uU(5): feof(false) #1 {main} thrown in /in/3h3uU on line 5
Process exited with code 255.
Output for rfc.property-hooks
Warning: fopen(): open_basedir restriction in effect. File(music_asdlist.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/3h3uU on line 2 Warning: fopen(music_asdlist.txt): Failed to open stream: Operation not permitted in /in/3h3uU on line 2 Fatal error: Uncaught TypeError: feof(): Argument #1 ($stream) must be of type resource, false given in /in/3h3uU:5 Stack trace: #0 /in/3h3uU(5): feof(false) #1 {main} thrown in /in/3h3uU on line 5
Process exited with code 255.

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:
39.84 ms | 401 KiB | 8 Q