php-get

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i php-get

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

1.9 kB

Total Files

3

Last publish

Collaborators

  • mahdrentys