Skip to content

Instantly share code, notes, and snippets.

@inferno7291
Created September 19, 2016 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inferno7291/63207b2632c2178e3549b64e1a9576e5 to your computer and use it in GitHub Desktop.
Save inferno7291/63207b2632c2178e3549b64e1a9576e5 to your computer and use it in GitHub Desktop.
GET PHP on Javascript
/**
* var name = $_GET('name');
* OR
* var $_GET = $_GET(), name = $_GET['name']
*/
function $_GET(param) {
var vars = {};
window.location.href.replace( location.hash, '' ).replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function( m, key, value ) { // callback
vars[key] = value !== undefined ? value : '';
}
);
if (param) {
return vars[param] ? vars[param] : null;
}
return vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment