{"id":19324945,"url":"https://github.com/spatie/url","last_synced_at":"2025-05-13T21:12:07.843Z","repository":{"id":11060032,"uuid":"67992655","full_name":"spatie/url","owner":"spatie","description":"Parse, build and manipulate URL's","archived":false,"fork":false,"pushed_at":"2024-12-20T09:37:39.000Z","size":143,"stargazers_count":728,"open_issues_count":1,"forks_count":58,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-28T17:09:38.471Z","etag":null,"topics":["build","manipulate","php","url"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source?search=\u0026sort=-downloads","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie","custom":"https://spatie.be/open-source/support-us"}},"created_at":"2016-09-12T08:55:26.000Z","updated_at":"2025-04-04T04:41:10.000Z","dependencies_parsed_at":"2024-12-29T09:01:30.292Z","dependency_job_id":"73e314a1-9461-4b5a-b1e5-3d9896241223","html_url":"https://github.com/spatie/url","commit_stats":{"total_commits":129,"total_committers":31,"mean_commits":4.161290322580645,"dds":0.6511627906976745,"last_synced_commit":"b35a48188bfd6c2d37763915f0a31d98be408fa1"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Furl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Furl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Furl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Furl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/url/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254029008,"owners_count":22002284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build","manipulate","php","url"],"created_at":"2024-11-10T02:07:42.844Z","updated_at":"2025-05-13T21:12:02.805Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie","https://spatie.be/open-source/support-us"],"categories":[],"sub_categories":[],"readme":"# Parse, build and manipulate URLs\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/url.svg?style=flat-square)](https://packagist.org/packages/spatie/url)\n[![Tests](https://github.com/spatie/url/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/url/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/url.svg?style=flat-square)](https://packagist.org/packages/spatie/url)\n\nA simple package to deal with URLs in your applications.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/url\n```\n\n## Usage\n\n### Parse and transform a URL\n\nRetrieve any part of the URL:\n\n```php\nuse Spatie\\Url\\Url;\n\n$url = Url::fromString('https://spatie.be/opensource');\n\necho $url-\u003egetScheme(); // 'https'\necho $url-\u003egetHost(); // 'spatie.be'\necho $url-\u003egetPath(); // '/opensource'\n```\n\nTransform any part of the URL:\n\n\u003e **Note**\n\u003e the `Url` class is immutable.\n\n```php\n$url = Url::fromString('https://spatie.be/opensource');\n\necho $url-\u003ewithHost('github.com')-\u003ewithPath('spatie');\n// 'https://github.com/spatie'\n```\n\n### Scheme\n\nTransform the URL scheme.\n```php\n$url = Url::fromString('http://spatie.be/opensource');\n\necho $url-\u003ewithScheme('https'); // 'https://spatie.be/opensource'\n```\n\nUse a list of allowed schemes.\n\n\u003e **Note**\n\u003e each scheme in the list will be sanitized\n\n```php\n$url = Url::fromString('https://spatie.be/opensource');\n\necho $url-\u003ewithAllowedSchemes(['wss'])-\u003ewithScheme('wss'); // 'wss://spatie.be/opensource'\n```\n\nor pass the list directly to `fromString` as the URL's scheme will be sanitized and validated immediately:\n\n```php\n$url = Url::fromString('https://spatie.be/opensource', [...SchemeValidator::VALID_SCHEMES, 'wss']);\n\necho $url-\u003ewithScheme('wss'); // 'wss://spatie.be/opensource'\n```\n\n\n### Query parameters\n\nRetrieve and transform query parameters:\n\n```php\n$url = Url::fromString('https://spatie.be/opensource?utm_source=github\u0026utm_campaign=packages');\n\necho $url-\u003egetQuery(); // 'utm_source=github\u0026utm_campaign=packages'\n\necho $url-\u003egetQueryParameter('utm_source'); // 'github'\necho $url-\u003egetQueryParameter('utm_medium'); // null\necho $url-\u003egetQueryParameter('utm_medium', 'social'); // 'social'\necho $url-\u003egetQueryParameter('utm_medium', function() {\n    //some logic\n    return 'email';\n}); // 'email'\n\necho $url-\u003ewithoutQueryParameter('utm_campaign'); // 'https://spatie.be/opensource?utm_source=github'\necho $url-\u003ewithQueryParameters(['utm_campaign' =\u003e 'packages']); // 'https://spatie.be/opensource?utm_source=github\u0026utm_campaign=packages'\n```\n\n### Path segments\n\nRetrieve path segments:\n\n```php\n$url = Url::fromString('https://spatie.be/opensource/laravel');\n\necho $url-\u003egetSegment(1); // 'opensource'\necho $url-\u003egetSegment(2); // 'laravel'\n```\n\n### PSR-7 `UriInterface`\n\nImplements PSR-7's `UriInterface` interface:\n\n```php\nclass Url implements UriInterface { /* ... */ }\n```\n\nThe [`league/uri`](https://github.com/thephpleague/uri) is a more powerful package than this one. The main reason this package exists, is because the alternatives requires non-standard php extensions. If you're dealing with special character encodings or need bulletproof validation, you're definitely better off using `league/uri`.\n\nSpatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/url.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/url)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Sebastian De Deyne](https://github.com/sebastiandedeyne)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Furl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Furl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Furl/lists"}