PHP URLs
ADVERTISEMENTS
The URL extension is to deal with URL strings: encoding, decoding, and parsing, etc.
Example to encode an URL into base64
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
Output
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==
Example to decode base64 string into a normal string
<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>
Output
This is an encoded string
Requirements
No external libraries are needed to build this extension.
Installation
There is no installation needed to use these functions; they are part of the PHP core.
Run-time Configuration
This extension has no configuration directives defined in php.ini.
Resource Types
This extension has no resource types defined.
Predefined Constants
This extension provided some predefined constants:
- PHP_URL_SCHEME - (integer)
- PHP_URL_HOST - (integer)
- Outputs the hostname of the URL parsing.
- PHP_URL_PORT - (integer)
- Outputs the port of the URL parsed.
- PHP_URL_USER - (integer)
- Outputs the user of the URL parsing.
- PHP_URL_PASS - (integer)
- Outputs the password of the URL parsed.
- PHP_URL_PATH - (integer)
- Outputs the path of the URL parsing.
- PHP_URL_QUERY - (integer)
- Outputs the query string of the URL parsed.
- PHP_URL_FRAGMENT - (integer)
- Outputs the fragment (the string after the hashmark #) of the URL parsed.
- The following constants are meant to be used with http_build_query().
- 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).
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