Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $parsedUrl = parse_url($uri);
- // if the uri has no scheme, it won't think there's a host and will give bad results
- if ($parsedUrl !== false && !isset($parsedUrl['host'])) {
- // double slash prepended will parse $uri as if it has a schema and no schema will be in the result
- $parsedUrl = parse_url('//' . $uri);
- }
- if ($parsedUrl === false) {
- throw new MalformedUrlException('Malformed URL: ' . $uri);
- }
- // use parsed url as needed
Add Comment
Please, Sign In to add comment