| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- // Christopher Pei
- // April 12, 2021
- if (isset($argv[1])){
-
- if (file_exists($argv[1])){
-
- $input_file = fopen($argv[1], "r") or die("Unable to open file.");
- $input = fread($input_file, filesize($argv[1]));
- fclose($input_file);
-
- $values = explode(',', $input);
- $unique = array();
-
- foreach ($values as $value){
-
- if (!in_array((string)$value, $unique)){
- array_push($unique, (string)$value);
- }
- }
-
- echo "\n Results\n =========================\n";
- foreach ($unique as $u){
- echo " " . $u . "\n";
- }
-
- return 0;
- }
-
- else{
-
- echo " > Sorry, file '" . $argv[1] . "' does not exist.\n";
- return 1;
- }
- }
- else{
- echo "\n Incorrect Syntax\n =========================\n";
- echo " > Missing filename with values.\n";
- echo "\n > Usage Example:\n";
- echo " > \"php " . $argv[0] . " values.txt\n";
- return 1;
- }
|