Skip to content

Instantly share code, notes, and snippets.

@legale
Forked from jlong/uri.js
Last active January 12, 2018 20:06
Show Gist options
  • Save legale/82930a6a783f61fe5f6091d37fc738b6 to your computer and use it in GitHub Desktop.
Save legale/82930a6a783f61fe5f6091d37fc738b6 to your computer and use it in GitHub Desktop.
php parse_url() JS analog
function parse_url(uri){
var a = document.createElement('a');
a.href = uri;
return {scheme: a.protocol, user: a.username, pass: a.password,
host: a.hostname, port: a.port, path: a.pathname,
query: a.search, fragment: a.hash
}
}
//demo
parse_url("http://user:password@example.com:3000/pathname/?search=test#hash");
@legale
Copy link
Author

legale commented Jan 12, 2018

js analog of the php function parse_url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment