downcode.php 599 B

1234567891011121314151617181920
  1. <?php
  2. //Downcode the provided argument or stdin if the argument was not present
  3. require_once dirname (__DIR__) . '/URLify.php';
  4. //Print usage and exit if arguments are invalid
  5. if($argc < 1 || $argc > 2) {
  6. die ("Usage (argument): php " . basename(__FILE__) . " \"<text to downcode>\"\nUsage (pipe): <Arbitrary command> | php " . basename(__FILE__) . "\n");
  7. }
  8. //Process the provided argument
  9. if($argc === 2) {
  10. $s = $argv[1];
  11. //Or read from stdin if the argument wasn't present
  12. } else {
  13. $piped = true;
  14. $s = file_get_contents("php://stdin");
  15. }
  16. echo URLify::downcode ($s) . ($piped ? "\n" : "");