PHP Function Reference


The PHP has a number of functions to deal with URL strings which involves encoding, decoding and parsing of a URL string.


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

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.

PHP_URL_HOSTIntegerOutputs the hostname of the URL parsed.
PHP_URL_PORTIntegerOutputs the port of the URL parsed.
PHP_URL_USERIntegerOutputs the user of the URL parsed
PHP_URL_PASSIntegerOutputs the password of the URL parsed.
PHP_URL_PATHIntegerOutputs the path of the URL parsed.
PHP_URL_QUERYIntegerOutputs the query string of the URL parsed.
PHP_URL_FRAGMENTIntegerOutputs the fragment (string after #) of the URL parsed.

The following constants are meant to be used with http_build_query() function.

PHP_QUERY_RFC1738IntegerEncoding 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_RFC3986IntegerEncoding is performed according to RFC 3986, and spaces will be percent encoded (%20).