Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prinx/url
URL utilities for PHP
https://github.com/prinx/url
Last synced: 15 days ago
JSON representation
URL utilities for PHP
- Host: GitHub
- URL: https://github.com/prinx/url
- Owner: prinx
- Created: 2021-07-09T08:30:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-09T09:16:58.000Z (over 3 years ago)
- Last Synced: 2024-12-02T03:47:53.813Z (about 1 month ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URL
URL utilities for PHP
## Installation
```shell
composer require prinx/url
```## Usage
### Create an instance of the utility class
```php
$url = new \Prinx\Url;
```### Add query string to URL
```php
$newUrl = $url->addQueryString('https://test.com', ['action' => 'test']); // https://test.com?action=test
$newUrl = $url->addQueryString('https://test.com?name=url', ['action' => 'test']); // https://test.com?name=url&action=test
```### Get URL parts
```php
$urlParts = $url->getParts('https://test.com?name=url');/*
[
'scheme' => 'https'
'host' => 'test.com'
'path' => '/path/'
'query' => 'query=string&action=test&name=url'
]
*/
``````php
$urlParts = $url->getParts('https://user:[email protected]:85/path/?action=test&name=url#faq');/*
[
'scheme' => 'https'
'host' => 'test.com'
'port' => 85
'user' => 'user'
'pass' => 'password'
'path' => '/path/'
'query' => 'action=test&name=url'
'fragment' => 'faq'
]
*/
```### Get query string
```php
$queryStrings = $url->getQueryStrings('https://test.com?name=url&action=test');// ['name' => 'url', 'action' => 'test']
```### Remove query string from URL
```php
$newUrl = $url->removeQueryString('https://test.com?name=url&action=test', 'name');// https://test.com?action=test
``````php
$newUrl = $url->removeQueryString('https://test.com?name=url&action=test', ['name', 'action']);// https://test.com
```## Contribute
Star :star: the repo, fork it, fix a bug, add a new feature, write tests, correct documentation, and submit a pull request.
## License
[MIT](LICENSE)