PHP code example of clue / arguments
1. Go to this page and download the library: Download clue/arguments library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
clue / arguments example snippets
(true) {
$line = fgets(STDIN, 1024);
$args = Clue\Arguments\split($line);
$command = array_shift($args);
if ($command === 'exit') {
break;
} elseif ($command === 'sleep') {
sleep($args[0]);
} elseif ($command === 'echo') {
echo join(' ', $args) . PHP_EOL;
} else {
echo 'Invalid command' . PHP_EOL;
}
}
use Clue\Arguments;
Arguments\split(…);
\Clue\Arguments\split(…);
// example command syntax:
// addUser <username> <realname> <homepage> <comment>
$line = 'adduser example Demo example.com Hi!';
$args = Arguments\split($line);
assert(count($args) === 5);
assert($args[0] === 'adduser');
assert($args[1] === 'example');
assert($args[2] === 'Demo');
assert($args[3] === 'example.com');
assert($args[4] === 'Hi!');
$line = 'adduser clue \'Christian Lück\' https://lueck.tv/ "Hällo\tWörld\n"';
$args = Arguments\split($line);
assert(count($args) === 5);
assert($args[0] === 'adduser');
assert($args[1] === 'clue');
assert($args[2] === 'Christian Lück');
assert($args[3] === 'https://lueck.tv');
assert($args[4] === "Hällo\tWörld\n");
$line = 'sendmail "" clue';
$args = Arguments\split($line);
assert(count($args) === 3);
assert($args[0] === 'sendmail');
assert($args[1] === '');
assert($args[2] === 'clue');
$line = "\r\n";
$args = Arguments\split($line);
assert(count($args) === 0);
$line = 'sendmail "hello world';
try {
Arguments\split($line);
// throws RuntimeException
} catch (Arguments\UnclosedQuotesException $e) {
echo 'Please check your input.';
}
$quotes = $e->getQuotes();
$line = 'sendmail "hello world';
try {
$args = Arguments\split($line);
// throws RuntimeException
} catch (Arguments\UnclosedQuotesException $e) {
// retry parsing with closing quotes appended
$args = Arguments\split($line . $e->getQuotes());
}
$pos = $e->getPosition();
assert($pos === 9);
assert($line[$pos] === $e->getQuotes());