downcode.php 698 B

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