{"id":16329271,"url":"https://github.com/josantonius/php-url","last_synced_at":"2025-03-20T22:32:00.988Z","repository":{"id":57001561,"uuid":"80688595","full_name":"josantonius/php-url","owner":"josantonius","description":"PHP library to access URL information","archived":false,"fork":false,"pushed_at":"2022-09-29T21:30:56.000Z","size":1184,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T18:33:44.541Z","etag":null,"topics":["php","php-url","url","url-details","url-info"],"latest_commit_sha":null,"homepage":"https://josantonius.dev","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/josantonius.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["Josantonius"]}},"created_at":"2017-02-02T03:08:58.000Z","updated_at":"2024-06-07T08:58:09.000Z","dependencies_parsed_at":"2022-08-21T11:40:48.339Z","dependency_job_id":null,"html_url":"https://github.com/josantonius/php-url","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josantonius","download_url":"https://codeload.github.com/josantonius/php-url/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244704022,"owners_count":20496228,"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":["php","php-url","url","url-details","url-info"],"created_at":"2024-10-10T23:14:58.462Z","updated_at":"2025-03-20T22:32:00.617Z","avatar_url":"https://github.com/josantonius.png","language":"PHP","funding_links":["https://github.com/sponsors/Josantonius"],"categories":[],"sub_categories":[],"readme":"# PHP URL library\n\n[![Latest Stable Version](https://poser.pugx.org/josantonius/url/v/stable)](https://packagist.org/packages/josantonius/url)\n[![License](https://poser.pugx.org/josantonius/url/license)](LICENSE)\n[![Total Downloads](https://poser.pugx.org/josantonius/url/downloads)](https://packagist.org/packages/josantonius/url)\n[![CI](https://github.com/josantonius/php-url/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/josantonius/php-url/actions/workflows/ci.yml)\n[![CodeCov](https://codecov.io/gh/josantonius/php-url/branch/main/graph/badge.svg)](https://codecov.io/gh/josantonius/php-url)\n[![PSR1](https://img.shields.io/badge/PSR-1-f57046.svg)](https://www.php-fig.org/psr/psr-1/)\n[![PSR4](https://img.shields.io/badge/PSR-4-9b59b6.svg)](https://www.php-fig.org/psr/psr-4/)\n[![PSR12](https://img.shields.io/badge/PSR-12-1abc9c.svg)](https://www.php-fig.org/psr/psr-12/)\n\n**Translations**: [Español](.github/lang/es-ES/README.md)\n\nPHP library to access URL information.\n\nProvides an improved replacement for the access to the components of a URL offered by PHP's\n`parse_url` and `pathinfo` functions.\n\nThis library does not format the provided URL, it only makes it easier to access the components.\nFor something more advanced you can use something like `league/uri-components`.\n\n---\n\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Available Classes](#available-classes)\n  - [Url Class](#url-class)\n- [Usage](#usage)\n- [Tests](#tests)\n- [TODO](#todo)\n- [Changelog](#changelog)\n- [Contribution](#contribution)\n- [Sponsor](#sponsor)\n- [License](#license)\n\n---\n\n## Requirements\n\n- Operating System: Linux | Windows.\n\n- PHP versions: 8.1 | 8.2.\n\n## Installation\n\nThe preferred way to install this extension is through [Composer](http://getcomposer.org/download/).\n\nTo install **PHP URL library**, simply:\n\n```console\ncomposer require josantonius/url\n```\n\nThe previous command will only install the necessary files,\nif you prefer to **download the entire source code** you can use:\n\n```console\ncomposer require josantonius/url --prefer-source\n```\n\nYou can also **clone the complete repository** with Git:\n\n```console\ngit clone https://github.com/josantonius/php-url.git\n```\n\n## Available Classes\n\n### Url Class\n\n`Josantonius\\Url\\Url`\n\nCreate a new instance:\n\n```php\n/**\n * If no URL is provided, the URL of the current page will be generated.\n * \n * The generated URL will exclude ports 80 and 443 and include the rest.\n */\npublic function __construct(null|string $url = null);\n```\n\nGets authority:\n\n```php\n/**\n * The authority, in \"[user-info@][host][:port]\" format.\n *\n * @var string URL authority or empty string.\n */\npublic readonly string $authority;\n```\n\nGets the base URL:\n\n```php\n/**\n * The base URL, in \"[scheme:][//domain][:port]\" format.\n *\n * @var string Base URL or empty string.\n */\npublic readonly string $base;\n```\n\nGets the path basename:\n\n```php\n/**\n * The path basename, in \"[filename][.extension]\" format.\n *\n * @var string URL path basename or empty string.\n */\npublic readonly string $basename;\n```\n\nGets the path dirname:\n\n```php\n/**\n * The path dirname, in \"[dirname]\" format.\n *\n * @var string URL path dirname or empty string.\n */\npublic readonly string $dirname;\n```\n\nGets the path basename extension:\n\n```php\n/**\n * The path basename extension, in \"[extension]\" format.\n *\n * @var string URL path basename extension or empty string.\n */\npublic readonly string $extension;\n```\n\nGets the path filename:\n\n```php\n/**\n * The path filename, in \"[filename]\" format.\n *\n * @var string URL path filename or empty string.\n */\npublic readonly string $filename;\n```\n\nGets fragment:\n\n```php\n/**\n * URL fragment in \"[fragment]\" format.\n *\n * @var string URL fragment or empty string.\n */\npublic readonly string $fragment;\n```\n\nGets the full URL:\n\n```php\npublic readonly string $full;\n```\n\nGets hashed fragment:\n\n```php\n/**\n * URL hashed fragment in \"[#fragment]\" format.\n *\n * @var string URL hashed fragment or empty string.\n */\npublic readonly string $hash;\n```\n\nGets host:\n\n```php\n/**\n * URL host in \"[subdomain.][domain][.tld]\" format.\n *\n * @var string URL host or empty string.\n */\npublic readonly string $host;\n```\n\nGets path:\n\n```php\n/**\n * URL path in \"[path]\" format.\n *\n * @var string URL path or empty string.\n */\npublic readonly string $path;\n```\n\nGets the query parameters:\n\n```php\n/**\n * URL query parameters in array format.\n *\n * @var array\u003cstring, mixed\u003e URL query parameters or empty string.\n */\npublic readonly array $parameters;\n```\n\nGets password:\n\n```php\n/**\n * URL password in \"[password]\" format.\n *\n * @var string URL password or empty string.\n */\npublic readonly string $password;\n```\n\nGets port:\n\n```php\n/**\n * URL port in \"[port]\" format.\n *\n * @var string URL port or empty string.\n */\npublic readonly int|string $port;\n```\n\nGets scheme:\n\n```php\n/**\n * URL scheme in \"[scheme]\" format.\n *\n * @var string URL scheme or empty string.\n */\npublic readonly string $scheme;\n```\n\nGets path segments:\n\n```php\n/**\n * URL path segments in array format.\n *\n * @var string[] URL path segments or empty string.\n */\npublic readonly array $segments;\n```\n\nGets query:\n\n```php\n/**\n * URL query in \"[query]\" format.\n *\n * @var string URL query or empty string.\n */\npublic readonly string $query;\n```\n\nGets username:\n\n```php\n/**\n * URL username in \"[username]\" format.\n *\n * @var string URL username or empty string.\n */\npublic readonly string $username;\n```\n\n## Usage\n\nExample of use for this library:\n\n### Create a new instance using the current URL\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url();\n```\n\n### Create a new instance using custom URL\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url('https://domain.com');\n```\n\n### Gets authority\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com\n\n$url-\u003eauthority;  // \"domain.com\"\n\n\n$url = new Url('https://user:pass@sub.domain.com:90/en/');\n\n$url-\u003eauthority; // \"user:pass@sub.domain.com:90\"\n\n\n$url = new Url('https://user:pass@sub.domain.com/en/');\n\n$url-\u003eauthority; // \"user:pass@sub.domain.com\"\n\n\n$url = new Url('https://sub.domain.com/en/');\n\n$url-\u003eauthority; // \"sub.domain.com\"\n```\n\n### Gets base URL\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://user:pass@domain.com:80/en/\n\n$url-\u003ebase; // \"https://domain.com\"\n\n\n$url = new Url('https://domain.com:80/?tag=bug');\n\n$url-\u003ebase; // \"https://domain.com:80\"\n\n\n$url = new Url('https://domain.com/en/');\n\n$url-\u003ebase; // \"https://domain.com\"\n```\n\n### Gets the path basename\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com/search.php\n\n$url-\u003ebasename; // \"search.php\"\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php?tag=bug');\n\n$url-\u003ebasename; // \"search.php\"\n\n\n$url = new Url('https://domain.com/en/web/docs?tag=bug');\n\n$url-\u003ebasename; // \"docs\"\n```\n\n### Gets the path dirname\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com/search.php\n\n$url-\u003edirname; // \"/\"\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php?tag=bug');\n\n$url-\u003edirname; // \"/en/web/docs\"\n\n\n$url = new Url('https://domain.com/en/web/docs?tag=bug');\n\n$url-\u003edirname; // \"/en/web\"\n```\n\n### Gets the path basename extension\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com/search.php\n\n$url-\u003eextension; // \"php\"\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php?tag=bug');\n\n$url-\u003eextension; // \"php\"\n\n\n$url = new Url('https://domain.com/en/web/docs?tag=bug');\n\n$url-\u003eextension; // \"\"\n```\n\n### Gets the path filename\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com/search.php\n\n$url-\u003efilename; // \"search\"\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php?tag=bug');\n\n$url-\u003efilename; // \"search\"\n\n\n$url = new Url('https://domain.com/docs?tag=bug');\n\n$url-\u003efilename; // \"docs\"\n```\n\n### Gets fragment\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com#top\n\n$url-\u003efragment; // \"top\"\n\n\n$url = new Url('https://domain.com/en/web/docs#top');\n\n$url-\u003efragment; // \"top\"\n\n\n$url = new Url('https://domain.com');\n\n$url-\u003efragment; // \"\"\n```\n\n### Gets the full URL\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com:80\n\n$url-\u003efull;  // \"https://domain.com\"\n\n\n$url = new Url('https://user:pass@sub.domain.com:90/en/');\n\n$url-\u003efull; // \"https://user:pass@sub.domain.com:90/en/\"\n```\n\n### Gets hashed fragment\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com#top\n\n$url-\u003ehash; // \"#top\"\n\n\n$url = new Url('https://domain.com/en/web/docs#top');\n\n$url-\u003ehash; // \"#top\"\n\n\n$url = new Url('https://domain.com');\n\n$url-\u003ehash; // \"\"\n```\n\n### Gets host\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://sub.domain.com\n\n$url-\u003ehost; // \"sub.domain.com\"\n\n\n$url = new Url('https://sub.domain.com/en/web/docs#top');\n\n$url-\u003ehost; // \"sub.domain.com\"\n\n\n$url = new Url('https://domain.com');\n\n$url-\u003ehost; // \"domain.com\"\n\n\n$url = new Url('https://localhost');\n\n$url-\u003ehost; // \"localhost\"\n```\n\n### Gets path\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com/en\n\n$url-\u003epath; // \"/en/web/docs/search.php\"\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php');\n\n$url-\u003epath; // \"/en/web/docs/search.php\"\n\n\n$url = new Url('https://domain.com/en/web/docs/');\n\n$url-\u003epath; // \"/en/web/docs/\"\n\n\n$url = new Url('https://domain.com/en?tag=bug');\n\n$url-\u003epath; // \"/en\"\n\n\n$url = new Url('https://domain.com?tag=bug');\n\n$url-\u003epath; // \"\"\n```\n\n### Gets the query parameters\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com/en?tag=bug\u0026order=asc#top\n\n$url-\u003eparameters; // [\"tag\" =\u003e \"bug\", \"order\" =\u003e \"asc\"]\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php');\n\n$url-\u003eparameters; // \"\"\n```\n\n### Gets password\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://:pass@domain.com\n\n$url-\u003epassword; // \"pass\"\n\n\n$url = new Url('https://user:pass@domain.com');\n\n$url-\u003epassword; // \"pass\"\n\n\n$url = new Url('https://user@domain.com');\n\n$url-\u003epassword; // \"\"\n```\n\n### Gets port\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com:90\n\n$url-\u003eport; // 90\n\n\n$url = new Url(); // https://domain.com:80\n\n$url-\u003eport; // \"\"\n\n\n$url = new Url(); // https://domain.com:443\n\n$url-\u003eport; // \"\"\n\n\n$url = new Url('https://domain.com:80/en/');\n\n$url-\u003eport; // 80\n\n\n$url = new Url('https://domain.com:443/en/');\n\n$url-\u003eport; // 443\n\n\n$url = new Url('https://domain.com/en/');\n\n$url-\u003eport; // \"\"\n```\n\n### Gets scheme\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // http://domain.com\n\n$url-\u003escheme; // \"http\"\n\n\n$url = new Url('https://domain.com');\n\n$url-\u003escheme; // \"https\"\n```\n\n### Gets path segments\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com?tag=bug\n\n$url-\u003esegments; // []\n\n\n$url = new Url('https://domain.com/en/web/docs/search.php');\n\n$url-\u003esegments; // ['en', 'web', 'docs', 'search.php']\n```\n\n### Gets query\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://domain.com?tag=bug\n\n$url-\u003equery; // \"tag=bug\"\n\n\n$url = new Url('https://domain.com?tag=bug\u0026order=asc#top');\n\n$url-\u003equery; // \"tag=bug\u0026order=asc\"\n\n$url = new Url('https://domain.com');\n\n$url-\u003equery; // \"\"\n```\n\n### Gets username\n\n```php\nuse Josantonius\\Url\\Url;\n\n$url = new Url(); // https://user@domain.com\n\n$url-\u003eusername; // \"user\"\n\n\n$url = new Url('https://:pass@domain.com');\n\n$url-\u003eusername; // \"\"\n\n\n$url = new Url('https://user:pass@domain.com');\n\n$url-\u003eusername; // \"user\"\n\n\n$url = new Url('https://domain.com');\n\n$url-\u003eusername; // \"\"\n```\n\n## Tests\n\nTo run [tests](tests) you just need [composer](http://getcomposer.org/download/)\nand to execute the following:\n\n```console\ngit clone https://github.com/josantonius/php-url.git\n```\n\n```console\ncd php-url\n```\n\n```console\ncomposer install\n```\n\nRun unit tests with [PHPUnit](https://phpunit.de/):\n\n```console\ncomposer phpunit\n```\n\nRun code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):\n\n```console\ncomposer phpcs\n```\n\nRun [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:\n\n```console\ncomposer phpmd\n```\n\nRun all previous tests:\n\n```console\ncomposer tests\n```\n\n## TODO\n\n- [ ] Add new feature\n- [ ] Improve tests\n- [ ] Improve documentation\n- [ ] Improve English translation in the README file\n- [ ] Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)\n\n## Changelog\n\nDetailed changes for each release are documented in the\n[release notes](https://github.com/josantonius/php-url/releases).\n\n## Contribution\n\nPlease make sure to read the [Contributing Guide](.github/CONTRIBUTING.md), before making a pull\nrequest, start a discussion or report a issue.\n\nThanks to all [contributors](https://github.com/josantonius/php-url/graphs/contributors)! :heart:\n\n## Sponsor\n\nIf this project helps you to reduce your development time,\n[you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work :blush:\n\n## License\n\nThis repository is licensed under the [MIT License](LICENSE).\n\nCopyright © 2017-present, [Josantonius](https://github.com/josantonius#contact)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosantonius%2Fphp-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosantonius%2Fphp-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosantonius%2Fphp-url/lists"}