<<css mode="next" class="sidebar"></css>> (((
- '''<a href="/docs/fURL">Class Documentation</a>''' - <a href="/api/fURL">API Reference</a> - <a href="https://github.com/flourishlib/flourish-classes/blob/master/fURL.php" target="_blank">Source Code</a>
<<toc></toc>> )))
The fURL class provides a simple and useful set of features for dealing with URLs in your site or application.
There are a few static methods that allow retrieval of URL information. All of these static methods return information about the URL as requested by the browser. All server-side rewrites are ignored.
|| Method || Description || || ::get() || Returns the current URL minus the query string and domain name || || ::getQueryString() || Returns the current query string || || ::getWithQueryString() || Returns the current URL minus the domain name || || ::getDomain() || Returns the current domain name with protocol prefix ||
Here are examples of them being used:
Beyond simply retrieving information about the URL, the fURL class also provides some functionality to modify the query string.
The ::replaceInQueryString() and ::removeFromQueryString() methods allow addition/replacement and deletion of a values in the query string, respectively. Similar to the various `get` methods, these methods work with the URL before any server-side rewrites were applied.
`replaceInQueryString()` takes two parameters, `$key` and `$value`. Any existing value for the key will be replaced. If no value exists for the key, the key will be added with the new value. Here is the method in use:
`removeFromQueryString()` takes any number of parameters with each one being a `GET` key/field. Any matching key in the query string will be removed. Here is an example of the method in action:
The ::redirect() method was built to simplify the task of redirecting a user to another web page. Simply pass the name of the site/page to redirect to as the only parameter and the method will determine the type of link it is (relative, web server absolute, etc.).
Since headers can only be sent before content, you will either need to ensure no content has been sent to the user yet, or that output buffering has been enabled. The fBuffer class may be of interest if you are going to use output buffering.
The method will redirect to almost any URL provided, and will do so in standard-compliant way by sending a fully-formed (including protocol and domain name) URL in the HTTP headers. Here are some examples of how to use the `redirect()` method:
When creating websites with friendly URLs it is useful to be able to convert the title of something into a human-readable url without having to worry about punctuation or characters with diacritics creating those nasty hexadecimal codes.
The ::makeFriendly() method performs this URL creation task. You can pass in any UTF-8 string and you will get back a URL made up of lowercase letters, numbers and the underscore character. All characters with diacritics will be converted to their plain counterparts.
Here are some examples:
It is possible to limit the character length of the generated string by passing a number to the optional second parameter `$max_length`.
By default ::makeFriendly() uses the `_` character to separate words. The optional third parameter, `$delimiter`, allows for changing this. If no length restriction is desired, the `$delimiter` can be passed as the second parameter.