{"id":28289189,"url":"https://github.com/wasinger/url","last_synced_at":"2025-08-02T02:38:01.340Z","repository":{"id":7373765,"uuid":"8700239","full_name":"wasinger/url","owner":"wasinger","description":"PHP class for handling and manipulating URLs","archived":false,"fork":false,"pushed_at":"2018-07-27T08:07:43.000Z","size":36,"stargazers_count":31,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-25T06:14:08.278Z","etag":null,"topics":["manipulating-urls","php","uri","uri-manipulations","url","url-parser"],"latest_commit_sha":null,"homepage":null,"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/wasinger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-11T09:36:51.000Z","updated_at":"2025-04-01T04:52:29.000Z","dependencies_parsed_at":"2022-09-22T13:02:45.161Z","dependency_job_id":null,"html_url":"https://github.com/wasinger/url","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/wasinger/url","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasinger%2Furl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasinger%2Furl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasinger%2Furl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasinger%2Furl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasinger","download_url":"https://codeload.github.com/wasinger/url/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasinger%2Furl/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268328785,"owners_count":24232939,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["manipulating-urls","php","uri","uri-manipulations","url","url-parser"],"created_at":"2025-05-22T00:14:27.888Z","updated_at":"2025-08-02T02:38:01.332Z","avatar_url":"https://github.com/wasinger.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"url\n===\n\nPHP class for handling and manipulating URLs. It's a pragmatic one-class lib that is completely framework independent.\n\n[![Build Status](https://secure.travis-ci.org/wasinger/url.svg?branch=master)](http://travis-ci.org/wasinger/url)\n[![Latest Version](http://img.shields.io/packagist/v/wa72/url.svg)](https://packagist.org/packages/wa72/url)\n\n\n- Parse URL strings to objects\n- add and modify query parameters\n- set and modify any part of the url\n- test for equality of URLs with query parameters in a PHP-fashioned way\n- supports protocol-relative urls\n- convert absolute, host-relative and protocol-relative urls to relative and vice versa\n\n- New in version 0.7 (2018/07/25): optional compatibility with  `Psr\\Http\\Message\\UriInterface` (PSR-7), see below\n\nInstallation\n------------\n\nThis package is listed on [Packagist](https://packagist.org/packages/wa72/url).\n\n```\ncomposer require wa72/url\n```\n\nFeatures and Usage\n------------------\n\n### Parse a URL to an object ###\n\n```php\nuse \\Wa72\\Url\\Url;\n\n$url = new Url('http://my-server.com/index.php?p1=foo\u0026p2=bar');\n// or alternatively use the static factory function `parse`:\n$url = Url::parse('http://my-server.com/index.php?p1=foo\u0026p2=bar');\n\n// set another host\n$url-\u003esetHost('another-server.org');\n\n// return the URL as string again\necho $url-\u003ewrite();\n// or simply:\necho $url;\n```\n\n### Easily modify and add query parameters ###\n\n```php\n$url-\u003esetQueryParameter('p1', 'newvalue');\n$url-\u003esetQueryParameter('param3', 'another value');\necho $url;\n// will output:\n// http://another-server.org/index.php?p1=newvalue\u0026p2=bar\u0026param3=another%20value\n\n// You can even add arrays a query parameter:\n$url-\u003esetQueryParameter('param3', array(5, 6));\necho $url;\n// will output:\n// http://another-server.org/index.php?p1=newvalue\u0026p2=bar\u0026param3[]=5\u0026param3[]=6\n```\n\n### Compare URLs with query strings the PHP way ###\n\nWhile in general a URL may have multiple query parameters with the same name \n(e.g. `?a=value1\u0026a=value2\u0026a=value3`) and there are web applications that convert\nthose parameters into an array, this is not the PHP way of dealing with query parameters:\nIn PHP, the last parameter with the same name always wins, so the \nabove query string is equal to only `?a=value3`.\n\nSimilarly, while in general the order of query parameters in the query string may\nbe significant to a web application, it is not in PHP: `?a=1\u0026b=2` is equivalent \nto `?b=2\u0026a=1` for a PHP application.\n\n`Url` deals with query strings in URLs like PHP does, so the URLs in the following\nexample are to be considered equal:\n\n```php\n$url1 = Url::parse('index.php?a=0\u0026a=1\u0026b=2');\n$url2 = Url::parse('index.php?b=2\u0026a=1');\n\nreturn $url1.equals($url2);\n// will return TRUE\n```\n\n### Make relative URL absolute ###\n\nA given URL that has \n\n- no scheme (protocol-relative URL)\n- no scheme and no host (host-relative URL)\n- no scheme, no host, and a relative path (relative URL)\n\ncan be turned into an absolute URL by a given base URL:\n\n```php\n$url = Url::parse('page.php');\n$baseurl = Url::parse('http://www.test.test/index.html');\n$url-\u003emakeAbsolute($baseurl);\necho $url; // will print: http://www.test.test/page.php\n\n$url = Url::parse('../de/seite.html');\n$baseurl = Url::parse('http://www.test.test/en/page.html');\n$url-\u003emakeAbsolute($baseurl);\necho $url; // will print: http://www.test.test/de/seite.html\n\n$url = Url::parse('/index.html');\n$baseurl = Url::parse('http://www.test.test/en/page.html');\n$url-\u003emakeAbsolute($baseurl);\necho $url; // will print: http://www.test.test/index.html\n\n$url = Url::parse('/index.html');\n$baseurl = Url::parse('http://www.test.test/en/page.html');\n$url-\u003emakeAbsolute($baseurl);\necho $url; // will print: http://www.test.test/index.html\n\n$url = Url::parse('//www.test.test/index.html');\n$baseurl = Url::parse('https://www.test.test/en/page.html');\n$url-\u003emakeAbsolute($baseurl);\necho $url; // will print: https://www.test.test/index.html\n```\n\n### Output protocol-relative and host-relative URLs ###\n\nIf you want to omit the scheme, or scheme and host, when outputting the URL \nyou can pass `Url::WRITE_FLAG_OMIT_SCHEME` and with `Url::WRITE_FLAG_OMIT_HOST` to the `write()`-method:\n\n```php\n$url = Url::parse('https://www.test.test/index.php?id=5#c1');\n\n// protocol-relative output\necho $url-\u003ewrite(Url::WRITE_FLAG_OMIT_SCHEME); // will print: //www.test.test/index.php?id=5#c1\n\n// host-relative output\necho $url-\u003ewrite(Url::WRITE_FLAG_OMIT_SCHEME | Url::WRITE_FLAG_OMIT_HOST)); // will print: /index.php?id=5#c1\n```\n\n### Compatibility with `Psr\\Http\\Message\\UriInterface` (PSR-7) ###\n\n- class `Url` now has all methods defined in this interface but does not officially implement it.\n- new wrapper class `Psr7Uri` that implements `UriInterface`\n- methods for converting between `Url` and `Psr7Uri`\n\nClass `Url` does not implement the PSR Interface by itself for two reasons:\n1. To not introduce a new dependency on the PSR interface. The dependency is only \"suggested\" in composer json.\n2. Because the PSR interface is designed to be immutable,\n    while `Url` is not.\n\nTo use this feature, you need to `composer require psr/http-message`.\n\n```php\n\u003c?php\nuse Wa72\\Url\\Psr7Uri;\nuse Wa72\\Url\\Url;\n\n# Get a Psr7Uri from a Url object\n\n$url = Url::parse('https://www.foo.bar/test.php?a=b');\n$psr7uri = Psr7Uri::fromUrl($url);\n// or alternatively:\n$psr7uri = $url-\u003etoPsr7();\n\n# Get a Url object from UriInterface\n\n$url = Url::fromPsr7($psr7uri); // this works for every UriInterface object, not only Wa72\\Url\\Psr7Uri\n// or alternatively:\n$url = $psr7uri-\u003etoUrl();\n\n# You can also create a Psr7Uri directly\n\n$psr7uri = Psr7Uri::parse('https://www.foo.bar/test.php?a=b');\n```\n\n### More documentation to come ###\n\nMeanwhile, have a look at the source code, there are lots of comments in it.\n\n(c) Christoph Singer 2018. Licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasinger%2Furl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasinger%2Furl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasinger%2Furl/lists"}