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]; } } ?>

preferences:
37.62 ms | 402 KiB | 5 Q