PHP - URLs
The PHP has a number of functions to deal with URL strings which involves encoding, decoding and parsing of a URL string.
Installation
There is no installation needed to use these functions. These functions are part of the PHP core.
Runtime Configuration
This extension has no configuration directives defined in php.ini.
PHP URLs Functions
Functions | Description |
---|---|
base64_decode() | Decodes data encoded with MIME base64. |
base64_encode() | Encodes data with MIME base64. |
get_headers() | Fetches all the headers sent by the server in response to an HTTP request. |
get_meta_tags() | Extracts all meta tag content attributes from a file and returns an array. |
http_build_query() | Generate URL-encoded query string. |
parse_url() | Parse a URL and return its components. |
rawurldecode() | Decode URL-encoded strings. |
rawurlencode() | URL-encode according to RFC 3986. |
urldecode() | Decodes URL-encoded string. |
urlencode() | URL-encodes string. |
PHP URLs Predefined Constants
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
The following constants are meant to be used with parse_url() function.
Constants | Type | Description |
---|---|---|
PHP_URL_SCHEME | Integer | |
PHP_URL_HOST | Integer | Outputs the hostname of the URL parsed. |
PHP_URL_PORT | Integer | Outputs the port of the URL parsed. |
PHP_URL_USER | Integer | Outputs the user of the URL parsed |
PHP_URL_PASS | Integer | Outputs the password of the URL parsed. |
PHP_URL_PATH | Integer | Outputs the path of the URL parsed. |
PHP_URL_QUERY | Integer | Outputs the query string of the URL parsed. |
PHP_URL_FRAGMENT | Integer | Outputs the fragment (string after #) of the URL parsed. |
The following constants are meant to be used with http_build_query() function.
Constants | Type | Description |
---|---|---|
PHP_QUERY_RFC1738 | Integer | Encoding is performed per RFC 1738 and the application/x-www-form-urlencoded media type, which implies that spaces are encoded as plus (+) signs. |
PHP_QUERY_RFC3986 | Integer | Encoding is performed according to RFC 3986, and spaces will be percent encoded (%20). |