Get the subdomain from a URL

Anyone have any great ideas besides storing a list of all TLDs? No, because each TLD differs on what counts as a subdomain, second level domain, etc. Keep in mind that there are top level domains, second level domains, and subdomains. Technically speaking, everything except the TLD is a subdomain. In the domain.com.uk example, “domain” … Read more

How to validate a url in Python? (Malformed or not)

Use the validators package: >>> import validators >>> validators.url(“http://google.com”) True >>> validators.url(“http://google”) ValidationFailure(func=url, args={‘value’: ‘http://google’, ‘require_tld’: True}) >>> if not validators.url(“http://google”): … print “not valid” … not valid >>> Install it from PyPI with pip (pip install validators).

Java – class.getResource returns null

For those who use Intellij Idea: check for Settings > Build, Execution, Deployment > Compiler > Resource patterns. The setting contains all extensions that should be interpreted as resources. If an extension does not comply to any pattern here, class.getResource will return null for resources using this extension.

How to get multiple parameters with same name from a URL in PHP

Something like: $query = explode(‘&’, $_SERVER[‘QUERY_STRING’]); $params = array(); foreach( $query as $param ) { // prevent notice on explode() if $param has no ‘=’ if (strpos($param, ‘=’) === false) $param += ‘=’; list($name, $value) = explode(‘=’, $param, 2); $params[urldecode($name)][] = urldecode($value); } gives you: array( ‘ctx_ver’ => array(‘Z39.88-2004’), ‘rft_id’ => array(‘info:oclcnum/1903126’, ‘http://www.biodiversitylibrary.org/bibliography/4323’), ‘rft_val_fmt’ => … Read more

Get domain name from given url

If you want to parse a URL, use java.net.URI. java.net.URL has a bunch of problems — its equals method does a DNS lookup which means code using it can be vulnerable to denial of service attacks when used with untrusted inputs. “Mr. Gosling — why did you make url equals suck?” explains one such problem. … Read more

How to validate an url on the iPhone

Why not instead simply rely on Foundation.framework? That does the job and does not require RegexKit : NSURL *candidateURL = [NSURL URLWithString:candidate]; // WARNING > “test” is an URL according to RFCs, being just a path // so you still should check scheme and all other NSURL attributes you need if (candidateURL && candidateURL.scheme && … Read more