phpjs
Version:
61 lines (50 loc) • 1.95 kB
Markdown
layout: page
title: "JavaScript getenv function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/getenv:585
- /functions/view/getenv
- /functions/view/585
- /functions/getenv:585
- /functions/585
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's getenv
{% codeblock info/getenv.js lang:js https://raw.github.com/kvz/phpjs/master/functions/info/getenv.js raw on github %}
function getenv (varname) {
// From: http://phpjs.org/functions
// + original by: Brett Zamir (http://brett-zamir.me)
// % note 1: We are not using $_ENV as in PHP, you could define
// % note 1: "$_ENV = this.php_js.ENV;" and get/set accordingly
// % note 2: Returns e.g. 'en-US' when set global this.php_js.ENV is set
// % note 3: Uses global: php_js to store environment info
// * example 1: getenv('LC_ALL');
// * returns 1: false
if (!this.php_js || !this.php_js.ENV || !this.php_js.ENV[varname]) {
return false;
}
return this.php_js.ENV[varname];
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/info/getenv.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/info/getenv.js)
### Example 1
This code
{% codeblock lang:js example %}
getenv('LC_ALL');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
false
{% endcodeblock %}
### Other PHP functions in the info extension
{% render_partial _includes/custom/info.html %}