diff --git a/README.md b/README.md index 21a2904..d789a05 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # phpquoteshellarg -php quote shell arguments +php quote shell arguments function +... doing a better job than php's builtin escapeshellarg(): https://3v4l.org/Hkv7h + +# installation +the script is just a standalone .php file, you can just copypaste it. + +another alternative is to use composer: +``` +composer require 'divinity76/phpquoteshellarg' +``` +# usage + +``` +$str,"escapeshellarg"=>escapeshellarg($str), "quoteshellarg"=>quoteshellarg($str)]); +``` +may outputs something like +``` +array(3) { + ["str"]=> + string(7) "æøå" + ["escapeshellarg"]=> + string(3) "''" + ["quoteshellarg"]=> + string(9) "'æøå'" +} +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d289c32 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "divinity76/phpquoteshellarg", + "description": "php quote shell arguments", + "keywords": ["quoteshellarg", "escapeshellarg"], + "homepage": "https://github.com/divinity76/phprouter", + "type": "library", + "license": "Unlicense", + "require": { + "php": ">=7.2" + }, + "autoload": { + "psr-4": {"Divinity76\\": "src/Divinity76/"} + } +} diff --git a/src/Divinity76/quoteshellarg/quoteshellarg.php b/src/Divinity76/quoteshellarg/quoteshellarg.php new file mode 100644 index 0000000..fc0a5b5 --- /dev/null +++ b/src/Divinity76/quoteshellarg/quoteshellarg.php @@ -0,0 +1,33 @@ + "'\\''")) . "'"; + } + // todo: quoteshellarg for windows? it's a nightmare though: https://docs.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way + // fallback to php's builtin escapeshellarg + return escapeshellarg($arg); +}