Created
September 19, 2016 13:40
-
-
Save inferno7291/63207b2632c2178e3549b64e1a9576e5 to your computer and use it in GitHub Desktop.
GET PHP on Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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