phpjs
Version:
60 lines (48 loc) • 1.88 kB
Markdown
layout: page
title: "JavaScript escapeshellarg function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/escapeshellarg:866
- /functions/view/escapeshellarg
- /functions/view/866
- /functions/escapeshellarg:866
- /functions/866
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's escapeshellarg
{% codeblock exec/escapeshellarg.js lang:js https://raw.github.com/kvz/phpjs/master/functions/exec/escapeshellarg.js raw on github %}
function escapeshellarg (arg) {
// From: http://phpjs.org/functions
// + original by: Felix Geisendoerfer (http://www.debuggable.com/felix)
// + improved by: Brett Zamir (http://brett-zamir.me)
// * example 1: escapeshellarg("kevin's birthday");
// * returns 1: "'kevin\'s birthday'"
var ret = '';
ret = arg.replace(/[^\\]'/g, function (m, i, s) {
return m.slice(0, 1) + '\\\'';
});
return "'" + ret + "'";
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/exec/escapeshellarg.js)
Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are
the closest match to this hashtable-like data structure.
Please also note that php.js offers community built functions and goes by the
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online
functions that are far from perfect, in the hopes to spark better contributions.
Do you have one? Then please just:
- [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/exec/escapeshellarg.js)
### Example 1
This code
{% codeblock lang:js example %}
escapeshellarg("kevin's birthday");
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
"'kevin\'s birthday'"
{% endcodeblock %}
### Other PHP functions in the exec extension
{% render_partial _includes/custom/exec.html %}