PHP - URL Functions



PHP has a number of built-in functions for handling URLs. These programs can be used for encoding, decoding, parsing, and URL creation, with other functions.

These methods are useful when working with URLs in PHP because they improve the process of manipulating and extracting data from URLs.

Installation

Since PHP URL functions are built into the PHP core, no further installation is required. All you need to do is make sure PHP is installed on your server or in your development environment.

Requirements

These functions are supported by all versions of PHP. Make that the specific function you want to use is supported by the version of PHP you are using. Normally, the URL functions are supported by PHP 4 and later.

Runtime Configuration

There are no extra runtime changes needed while using PHP URL functions. They are ready to use. But make sure your PHP environment is configured properly in order to create websites. You can look at your php.ini file to see the standard PHP settings.

Predefined Constants

The constants listed below are defined by this extension and will only be available once it has been compiled into PHP or dynamically loaded at runtime.

The following constants are intended to be used with parse_url()

Sr.No Constant & Description
1 PHP_URL_SCHEME (int)

Outputs the scheme (protocol) of the URL parsed.

2 PHP_URL_HOST (int)

Outputs the hostname of the URL parsed.

3 PHP_URL_PORT (int)

Outputs the port of the URL parsed.

4 PHP_URL_USER (int)

Outputs the user of the URL parsed.

5 PHP_URL_PASS (int)

Outputs the password of the URL parsed.

6 PHP_URL_PATH (int)

Outputs the path of the URL parsed.

7 PHP_URL_QUERY (int)

Outputs the query string of the URL parsed.

8 PHP_URL_FRAGMENT (int)

Outputs the fragment (string after the hashmark #) of the URL parsed.

9 PHP_QUERY_RFC1738 (int)

Encoding is performed per RFC 1738 and the application/x-www-form-urlencoded media type, which implies that spaces are encoded as plus (+) signs.

10 PHP_QUERY_RFC3986 (int)

Encoding is performed according to RFC 3986, and spaces will be percent encoded (%20).

List of Functions

Here is the list of some common PHP URL functions −

Sr.No Function & Description
1

base64_decode() Function

This function can decode the data encoded with MIME base64.

2

base64_encode() Function

This function can encode the data with MIME base64.

3

get_headers() Function

This function can fetch all headers sent by the server in response to an HTTP request.

4

get_meta_tags() Function

This function can extract all meta tag content attributes from a file and can return an array.

5

http_build_query() Function

This function can generate a URL-encoded query string.

6

parse_url() Function

This function can parse a URL and return its components.

7

rawurldecode() Function

This function can decode a URL encoded strings.

8

rawurlencode() Function

This function is a URL encode according to RFC 3986.

9

urldecode() Function

This function can decode a URL encoded string.

10

urlencode() Function

This function is a URL-encodes string.

php_function_reference.htm
Advertisements