streams/vendor/jbroadway/urlify/scripts/downcode.php

26 lines
698 B
PHP
Raw Normal View History

2019-04-12 06:54:18 +00:00
<?php
2019-12-30 04:28:55 +00:00
//
// Downcode the provided argument or stdin if the argument was not present
//
2019-04-12 06:54:18 +00:00
2020-07-07 05:21:11 +00:00
require_once \dirname(__DIR__) . '/vendor/autoload.php';
2019-12-30 04:28:55 +00:00
require_once \dirname(__DIR__) . '/URLify.php';
// Print usage and exit if arguments are invalid
if ($argc < 1 || $argc > 2) {
die('Usage (argument): php ' . \basename(__FILE__) . " \"<text to downcode>\"\nUsage (pipe): <Arbitrary command> | php " . \basename(__FILE__) . "\n");
2019-04-12 06:54:18 +00:00
}
2019-12-30 04:28:55 +00:00
// Process the provided argument
2020-07-07 05:21:11 +00:00
$piped = false;
2019-12-30 04:28:55 +00:00
if ($argc === 2) {
$s = $argv[1];
// Or read from stdin if the argument wasn't present
2019-04-12 06:54:18 +00:00
} else {
2019-12-30 04:28:55 +00:00
$piped = true;
$s = \file_get_contents('php://stdin');
2019-04-12 06:54:18 +00:00
}
2019-12-30 04:28:55 +00:00
echo URLify::downcode($s) . ($piped ? "\n" : '');