diff options
-rw-r--r-- | search.php | 34 |
1 files changed, 29 insertions, 5 deletions
@@ -16,14 +16,27 @@ try { curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $output = json_decode(curl_exec($curl)); curl_close($curl); - - $search = "abel"; + $search = read_stdin(); + + if (empty($search)) { + throw new Exception("Please enter a search term"); + } + + $args = explode(" ", $search); // Really slow search $results = []; foreach ($output as $upload) { - if (strpos($upload->filename, $search) !== false) { + $match = false; + foreach ($args as $arg) { + if (strpos($upload->filename, $arg) === false) { + $match = false; + break; + } + $match = true; + } + if ($match) { $results[] = $config["url"] . "/" . $upload->filename; } } @@ -32,9 +45,20 @@ try { if (empty($results)) { echo "No results found\n"; } else { - var_dump($results);die(); + foreach($results as $result) { + echo $result . "\n"; + } } } catch (Exception $e) { - var_dump($e->getMessage());die(); + 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 }
\ No newline at end of file |