{"id":13410139,"url":"https://github.com/jwage/purl","last_synced_at":"2025-05-14T23:02:27.140Z","repository":{"id":6327636,"uuid":"7562889","full_name":"jwage/purl","owner":"jwage","description":"Purl is a simple Object Oriented URL manipulation library for PHP 7.2+","archived":false,"fork":false,"pushed_at":"2021-12-30T14:47:04.000Z","size":364,"stargazers_count":906,"open_issues_count":7,"forks_count":123,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-13T19:45:06.856Z","etag":null,"topics":["php","url"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"karan/HNify","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwage.png","metadata":{"files":{"readme":"README.markdown","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-01-11T16:24:20.000Z","updated_at":"2025-04-03T20:22:24.000Z","dependencies_parsed_at":"2022-08-21T14:10:55.630Z","dependency_job_id":null,"html_url":"https://github.com/jwage/purl","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fpurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fpurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fpurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fpurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwage","download_url":"https://codeload.github.com/jwage/purl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243353,"owners_count":22038044,"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","url"],"created_at":"2024-07-30T20:01:05.177Z","updated_at":"2025-05-14T23:02:27.031Z","avatar_url":"https://github.com/jwage.png","language":"PHP","funding_links":[],"categories":["URL","网址 URL","PHP","Table of Contents","目录"],"sub_categories":["URL","Globalization"],"readme":"Purl\n====\n\nPurl is a simple Object Oriented URL manipulation library for PHP 7.2+\n\n[![Build Status](https://secure.travis-ci.org/jwage/purl.png?branch=master)](http://travis-ci.org/jwage/purl)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/jwage/purl/badges/quality-score.png?s=7e0e1d4b5d7f6be61a3cd804dba556a0e4d1141d)](https://scrutinizer-ci.com/g/jwage/purl/)\n[![Code Coverage](https://scrutinizer-ci.com/g/jwage/purl/badges/coverage.png?s=a02332bc4d6a32df3171f2ba714e4583a70c0154)](https://scrutinizer-ci.com/g/jwage/purl/)\n[![Latest Stable Version](https://poser.pugx.org/jwage/purl/v/stable.png)](https://packagist.org/packages/jwage/purl)\n[![Total Downloads](https://poser.pugx.org/jwage/purl/downloads.png)](https://packagist.org/packages/jwage/purl)\n\n## Installation\n\nThe suggested installation method is via [composer](https://getcomposer.org/):\n\n```sh\ncomposer require jwage/purl\n```\n\nUsing Purl\n----------\n\nCreating Url instances is easy. You can specify the URL you want, or just use the current URL:\n\n```php\nuse Purl\\Url;\n\n$url = new Url('http://jwage.com');\n$currentUrl = Url::fromCurrent();\n```\n\nYou can chain methods together after creating the `Url` like this:\n\n```php\n$url = (new Url('http://jwage.com'))\n    -\u003eset('scheme', 'https')\n    -\u003eset('port', '443')\n    -\u003eset('user', 'jwage')\n    -\u003eset('pass', 'password')\n    -\u003eset('path', 'about/me')\n    -\u003eset('query', 'param1=value1\u0026param2=value2')\n    -\u003eset('fragment', 'about/me?param1=value1\u0026param2=value2');\n\necho $url-\u003egetUrl(); // https://jwage:password@jwage.com:443/about/me?param1=value1\u0026param2=value2#about/me?param1=value1\u0026param2=value2\n\n// $url-\u003epath becomes instanceof Purl\\Path\n// $url-\u003equery becomes instanceof Purl\\Query\n// $url-\u003efragment becomes instanceof Purl\\Fragment\n```\n\n### Path Manipulation\n\n```php\n$url = new Url('http://jwage.com');\n\n// add path segments one at a time\n$url-\u003epath-\u003eadd('about')-\u003eadd('me');\n\n// set the path data from a string\n$url-\u003epath = 'about/me/another_segment'; // $url-\u003epath becomes instanceof Purl\\Path\n\n// get the path segments\nprint_r($url-\u003epath-\u003egetData()); // array('about', 'me', 'another_segment')\n```\n\n### Query Manipulation\n\n```php\n$url = new Url('http://jwage.com');\n$url-\u003equery-\u003eset('param1', 'value1');\n$url-\u003equery-\u003eset('param2', 'value2');\n\necho $url-\u003equery; // param1=value1\u0026param2=value2\necho $url; // http://jwage.com?param1=value1\u0026param2=value2\n\n// set the query data from an array\n$url-\u003equery-\u003esetData([\n    'param1' =\u003e 'value1',\n    'param2' =\u003e 'value2'\n]);\n\n// set the query data from a string\n$url-\u003equery = 'param1=value1\u0026param2=value2'; // $url-\u003equery becomes instanceof Purl\\Query\nprint_r($url-\u003equery-\u003egetData()); //array('param1' =\u003e 'value1', 'param2' =\u003e 'value2')\n```\n\n### Fragment Manipulation\n\n```php\n$url = new Url('http://jwage.com');\n$url-\u003efragment = 'about/me?param1=value1\u0026param2=value2'; // $url-\u003efragment becomes instanceof Purl\\Fragment\n```\n\nA Fragment is made of a path and a query and comes after the hashmark (#).\n\n```php\necho $url-\u003efragment-\u003epath; // about/me\necho $url-\u003efragment-\u003equery; // param1=value1\u0026param2=value2\necho $url; // http://jwage.com#about/me?param1=value1\u0026param2=value2\n```\n\n### Extract URLs\n\nYou can easily extract urls from a string of text using the `extract` method:\n\n```php\n$string = 'some text http://google.com http://jwage.com';\n$urls = Url::extract($string);\n\necho $urls[0]; // http://google.com/\necho $urls[1]; // http://jwage.com/\n```\n\n### Join URLs\n\nYou can easily join two URLs together using Purl:\n\n```php\n$url = new Url('http://jwage.com/about?param=value#fragment');\n$url-\u003ejoin('http://about.me/jwage');\n\necho $url; // http://about.me/jwage?param=value#fragment\n```\n\nOr if you have another `Url` object already:\n\n```php\n$url1 = new Url('http://jwage.com/about?param=value#fragment');\n$url2 = new Url('http://about.me/jwage');\n$url1-\u003ejoin($url2);\n\necho $url1; // http://about.me/jwage?param=value#fragment\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwage%2Fpurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwage%2Fpurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwage%2Fpurl/lists"}