Absolute URLs omitting the protocol (scheme) in order to preserve the one of the current page

is this URL format safe to use for all browsers. I can’t say anything for sure, but you should be able to test it in different browsers. And is it a standard? Technically, it is called “network path reference” according to RFC 3986. Here is the scheme for it: relative-ref = relative-part [ “?” query … Read more

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 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

How to check whether a string is a valid HTTP URL?

Try this to validate HTTP URLs (uriName is the URI you want to test): Uri uriResult; bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; Or, if you want to accept both HTTP and HTTPS URLs as valid (per J0e3gan’s comment): Uri uriResult; bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && (uriResult.Scheme == … Read more