1) { throw new Exception("Too many page choices. Enter only one `#`"); } if (!empty($pages)) { // Set the page $page = substr($pages[0], 1); } if (!is_int((int)$page) || $page <= 0) { throw new Exception("Page `" . $page . "` is not valid"); } // remove the pagination from the search args $pos = array_search("#" . $page, $args); if ($pos) { $args[$pos] = null; } // Really slow search $results = []; foreach ($output as $upload) { $match = false; foreach ($args as $arg) { if (!is_null($arg) && strpos($upload->filename, $arg) === false) { $match = false; break; } $match = true; } if ($match) { $results[] = $config["url"] . "/" . $upload->filename; } } // Return results $out = ""; if (empty($results)) { echo "No results found\n"; } else { $count = count($results); $i = 0; $start = ($page-1)*3; $end = $start+2; if ($start > ($count-1)) { throw new Exception("No results for this page"); } foreach($results as $result) { if ($i < $start || $i > $end) { $i++; continue; } $out .= $result . "\n"; $i++; } if ($count > 3) { $out .= " - results (" . $count . ")\n"; } } echo $out; } catch (Exception $e) { echo $e->getMessage() . "\n";die(); } function read_stdin() { $fr=fopen("php://stdin","r"); // open our file pointer to read from stdin $input = fgets($fr,128); // read a maximum of 128 characters $input = rtrim($input); // trim any trailing spaces. fclose ($fr); // close the file handle return $input; // return the text entered }