Recommend this page to a friend! |
Classes of Josantonius | PHP URL Manipulation Library | README.md | Download |
|
DownloadPHP Url libraryLibrary for urls manipulation.
RequirementsThis library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher. InstallationThe preferred way to install this extension is through Composer. To install PHP Url library, simply:
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
You can also clone the complete repository with Git: $ git clone https://github.com/Josantonius/PHP-Url.git Or install it manually:
Available MethodsAvailable methods in this library: - Get URL from the current page:
# Return (string) ? current URL - Get base URL of the site:
- Get protocol from current or passed URL:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | URL from which to obtain protocol. | string | No | false | # Return (string) ? http or https - Check if it is a secure site (SSL):
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | URL to check protocol. | string | No | false | # Return (boolean) - Get the server name:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | URL to get domain. | string | No | false | # Return (string|false) ? server name or false - Get URI:
# Return (string) ? path/URL - Remove subdirectories from uri if they exist:
# Return (string) ? method1/method2/method3 - Set parameters from the url and return url without them:If a url is received as: http://www.web.com/&key=value&key-2=value params will be saved as GET values and return: http://www.web.com/. If a url is received as: http://www.web.com/?key=value&key-2=value GET parameters are maintained and return: http://www.web.com/.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | URL to get params. | string | No | false | # Return (string|false) ? URL without parameters - Get the server port:
# Return (int) ? server port - Add back slash if it does not exist at the end of the route:
This method will remove all slashes that are in the indicated position before adding them. E. g. | Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $uri | URI when add back slash. | string | Yes | | | $position | Place where the back slash is placed: 'top', 'end' or 'both'. | string | No | 'end' | # Return (string|false) ? path/url/ | /path/url | /path/url/ or false if a correct type is not entered. - Go to the previous url:
# Return (void) - Redirect to chosen url:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | The URL to redirect. | string | Yes | | # Return (void) - Converts plain text urls into HTML links:Second argument will be used as the url label
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | URL where link. | string | Yes | | | $custom | If provided, this is used for the link label. | string | No | null | # Return (string) ? returns the data with links created around urls - This function converts and url segment to an safe one:For example: It will also return all letters in lowercase.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $slug | URL slug to clean up. | string | Yes | | # Return (string) ? slug - Get all url parts based on a / seperator:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $uri | URI to segment. | string | No | null | # Return (string) ? segments - Get first item segment:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $segments | Segments. | mixed | Yes | | # Return (string) ? segment - Get last item segment:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $segments | Segments. | mixed | Yes | | # Return (string) ? segment Quick StartTo use this library with Composer:
Or If you installed it manually, use it:
UsageExample of use for this library: - Get URL from the current page:
- Get base URL of the site:
- Get protocol from URL:
- Check if it is a secure site (SSL):
- Get the server name:
- Get URI:
- Remove subdirectories from URI if they exist:
- Set parameters from the URL and return URL without them:
- Get the server port:
- Add back slash if it does not exist at the end of the route:
- Add back slash if it does not exist at the top of the route:
- Add back slash if it doesn't exist at the top and end of the route:
- Go to the previous URL:
- Redirect to chosen URL:
- Converts plain text URLS into HTML links:
- Converts plain text URLS into HTML links with custom name:
- Converts and URL segment to an safe one:
- Get all URL parts based on a / seperator:
- Get first item segment from string:
- Get first item segment from array:
- Get last item segment from string:
- Get last item segment from array:
TestsTo run tests you just need composer and to execute the following:
Run unit tests with PHPUnit:
Run PSR2 code standard tests with PHPCS:
Run PHP Mess Detector tests to detect inconsistencies in code style:
Run all previous tests:
? TODO
ContributeIf you would like to help, please take a look at the list of issues or the To Do checklist. Pull requests
Thank you to all the people who already contributed to this project! <img alt="peter279k" src="https://avatars2.githubusercontent.com/u/9021747?v=4&s=117" height="117" width="117"> | :---:| peter279k| RepositoryThe file structure from this repository was created with PHP-Skeleton. LicenseThis project is licensed under MIT license. See the LICENSE file for more info. Copyright2017 - 2018 Josantonius, josantonius.com If you find it useful, let me know :wink: |