URL class intended for http and https schemes
This class allows you store absolute or relative URLs and access it's various parts (scheme, host, port, part, query, fragment).
It will also accept and attempt to resolve a relative URL against an absolute URL already stored.
Note: this URL class is based on the HTTP scheme.
Example:
1 $url =& new URL('http://www.domain.com/path/file.php?query=blah');
2 echo $url->get_scheme(),"\n"; // http
3 echo $url->get_host(),"\n"; // www.domain.com
4 echo $url->get_path(),"\n"; // /path/file.php
5 echo $url->get_query(),"\n"; // query=blah
6 // Setting a relative URL against our existing URL
7 $url->set_relative('../great.php');
8 echo $url->as_string();
See test_URL.php file for examples of how relative URLs are handled.
CHANGES:
Located in Program_Root/URL.php (line 69)
Constructor
Optional parameter accepts a URL string
As string
Returns the full URL (excluding any user info). Optional parameter allows you to specify whether you want the fragment (if available) to be included (default behaviour) in the resulting URL, or omitted. Passing false to as_string() will omit the fragment and crosshatch ('#') from the returned result.
URL_OPTION_WITH_FRAG (default) or URL_OPTION_NO_FRAG
Equal to
Returns true if $url is equal to current URL object. I'm hoping this method reflects RFC 2616 Section 3.2.3
Note: this method will not compare the following:
string URL or instance of URL class
Get fragment
Returns everything after the "#", or false if no fragment was specified
Get host
Returns the hostname/ip, or false if no hostname/ip was specified
Get password
Returns the password, or false if no password was specified.
Get path and query
Returns the path and (if available) the query
Get port
Returns the port number, or false if no port was specified.
If you pass true to get_port(), a default port will be returned if no port is found. This is based on checking if the URL is using the HTTP scheme (if so, 80 will be returned), or HTTPS scheme (if so, 443 will be returned).
(optional) default: false
Get query
Returns everything after the "?", or false if no query was specified
Get scheme
Returns the scheme, or false if no scheme was specified.
Get username
Returns the username, or false if no username was specified.
Set URL
Will overwrite all existing URL parts (see set_relative() to set a relative URL)
Set relative URL
Sets a URL as relative to the current URL (base). An absolute URL passed to this method will overwrite all existing URL parts stored. I'm hoping this method reflects RFC 2396 Section 5.2
Documention generated on Wed, 16 Jul 2003 01:04:00 +0100 by phpDocumentor 1.2.0