1.0.1 • Published 6 years ago

php-get v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

Php Get

Allows to get variables from PHP.

Installation

Download and install npm at www.npmjs.com/get-npm if you haven't already.

npm install php-get --save

This package is provided in ES6 module format.

Usage

To transmit variables to your js, you must write hidden input like this :

<input type="hidden" id="phpGet_var1" value="&quot;My example string&quot;" />
<input type="hidden" id="phpGet_var2" value="[&quot;The first element of my example array&quot;, &quot;The second element of my example array&quot;]" />

Notice that the value must be in JSON format, and that the double quotes are replaced with "&quot;". In js, you have to do that :

import phpGet from 'php-get';

var var1 = phpGet('var1');
var var2 = phpGet('var2');

console.log(var1); // We obtains : "My example string"
console.log(var2); // We obtains an array : ["The first element of my example array", "The second element of my example array"]

You can specify a default value, in case if the variable is not transmited. For example :

import phpGet from 'php-get';

var var3 = phpGet('var3', "This variable doesn't exists.");
console.log(var3); // We obtains : "This variable doesn't exists"

License

ISC