parse_url Parse a URL and return its components &reftitle.description; intstringarraynullfalseparse_url stringurl intcomponent-1 This function parses a URL and returns an associative array containing any of the various components of the URL that are present. The values of the array elements are not URL decoded. This function is not meant to validate the given URL, it only breaks it up into the parts listed below. Partial and invalid URLs are also accepted, parse_url tries its best to parse them correctly. &reftitle.parameters; url The URL to parse. component Specify one of PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT to retrieve just a specific URL component as a string (except when PHP_URL_PORT is given, in which case the return value will be an int). &reftitle.returnvalues; On seriously malformed URLs, parse_url may return &false;. If the component parameter is omitted, an associative array is returned. At least one element will be present within the array. Potential keys within this array are: scheme - e.g. http host port user pass path query - after the question mark ? fragment - after the hashmark # If the component parameter is specified, parse_url returns a string (or an int, in the case of PHP_URL_PORT) instead of an array. If the requested component doesn't exist within the given URL, &null; will be returned. As of PHP 8.0.0, parse_url distinguishes absent and empty queries and fragments: Previously all cases resulted in query and fragment being &null;. Note that control characters (cf. ctype_cntrl) in the components are replaced with underscores (_). &reftitle.changelog; &Version; &Description; 8.0.0 parse_url will now distinguish absent and empty queries and fragments. &reftitle.examples; A <function>parse_url</function> example ]]> &example.outputs; string(4) "http" ["host"]=> string(8) "hostname" ["port"]=> int(9090) ["user"]=> string(8) "username" ["pass"]=> string(8) "password" ["path"]=> string(5) "/path" ["query"]=> string(9) "arg=value" ["fragment"]=> string(6) "anchor" } string(4) "http" string(8) "username" string(8) "password" string(8) "hostname" int(9090) string(5) "/path" string(9) "arg=value" string(6) "anchor" ]]> A <function>parse_url</function> example with missing scheme ]]> &example.outputs; string(15) "www.example.com" ["path"]=> string(5) "/path" ["query"]=> string(17) "googleguy=googley" } ]]> &reftitle.notes; This function may not give correct results for relative or invalid URLs, and the results may not even match common behavior of HTTP clients. If URLs from untrusted input need to be parsed, extra validation is required, e.g. by using filter_var with the FILTER_VALIDATE_URL filter. This function is intended specifically for the purpose of parsing URLs and not URIs. However, to comply with PHP's backwards compatibility requirements it makes an exception for the file:// scheme where triple slashes (file:///...) are allowed. For any other scheme this is invalid. &reftitle.seealso; pathinfo parse_str http_build_query dirname basename RFC 3986