PHPackages                             zerig/url-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zerig/url-parser

ActiveLibrary

zerig/url-parser
================

class of object which parse url and can work with it.

v1.1.0(6y ago)0431MITPHPPHP &gt;=5.6.0

Since Apr 11Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Zerig/url-parser)[ Packagist](https://packagist.org/packages/zerig/url-parser)[ RSS](/packages/zerig-url-parser/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)DependenciesVersions (15)Used By (1)

URL-PARSER \\ URL
=================

[](#url-parser--url)

class which parse url and enable this URL for more operations.

```
$GLOBALS["server_root"] = new \UrlParser\Url("root");		// set root folder as ROOT
// BOTH variant are possile ↓
// during constructing URL obj, multiple slashes are transform to ONE
$url = new \UrlParser\Url(["http", "/www.web.cz/root", "/aaa/bbb", "a.html", "?member=me&age=15", "#hashtag"]);
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb//a.html?member=me&age=15#hashtag");

// special possibility for TEMPORARY files
$url = new \UrlParser\Url('C:\xampp\tmp\php8C07.tmp', '\\');

$url->getScheme("string")   => "http"
$url->getHost("string")     => "www.web.cz"
$url->getRoot("string")     => "root"
$url->getPath("string")     => "aaa/bbb/a.html"
$url->getQuery("string")    => "?member=me&age=15"
$url->getFragment("string") => "hashtag"
```

makeItString($url\_path)
------------------------

[](#makeitstringurl_path)

$url\_path \[string || array of string\]
Correct URL in right FORM. You can use STRING or ARRAYofSTRINGS to create url. This method also erase double slashes.

```
makeItString("http://www.web.cz//aaa/bbb/a.html")
makeItString(["http", "/www.web.cz/root", "/aaa/bbb", "a.html"])

getString() => "http://www.web.cz/root/aaa/bbb/a.html"
```

---

pop($times)
-----------

[](#poptimes)

- **$times \[int\]** How many time

- **@return \[string / array of string\]** What was popped

Remove last part of url PATH. NOT just print, but REMOVE!!!\\n

```
$url = new \UrlParser\Url("http://www.web.cz//aaa/bbb/a.html");
$url->getString() => "http://www.web.cz/root/aaa/bbb/a.html"

$popped = $url->pop();
$url->getString() => "http://www.web.cz/root/aaa/bbb"
$popped => "a.html"

$popped = $url->pop(3);
$url->getString() => "http://www.web.cz"
$popped => [
	[0] => "bbb",
	[1] => "aaa"
]
```

shift($times)
-------------

[](#shifttimes)

$times \[int\] How many time
Remove first part of url PATH. NOT just print, but REMOVE!!!

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->getString() => "http://www.web.cz/root/aaa/bbb/a.html"

$shifted = $url->shift();
$url->getString() => "http://www.web.cz/bbb/a.html"
$shifted => "aaa"

$shifted = $url->shift(3);
$url->getString() => "http://www.web.cz"
$shifted => [
	[0] => "bbb",
	[1] => "a.html"
]
```

swap($from, $to)
----------------

[](#swapfrom-to)

$from \[string\] which part of URL PATH should be changed
$to \[string\] changed to this
Change one part of URL PATH for a new one.

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->getString() => "http://www.web.cz/root/aaa/bbb/a.html"

$url->swap("aaa", "ccc");
$url->getString() => "http://www.web.cz/ccc/bbb/a.html"
```

---

get....($exp)
-------------

[](#getexp)

$exp \[string\] In which form do we want export

1. getScheme() - how is variable saved \[string | array of string | key array\]
2. getScheme("string") - how could be written in URL
3. getScheme("array") - in array \[array of string | key array\]

```
"http://web.cz/aaa/bbb/c.html"
```

- **getScheme()** - get scheme part: "http"
- **getHost()** - get Host part: "web.cz"
- **getRoot()** - get Root part: \["aaa"\]
- **getPath()** - get Path part: \["bbb", "a.html"\]
- **getQuery()** - get Query part: \["member" =&gt; "me", "age" =&gt; "15"\]
- **getFragment()** - get hastag part: "hashtag"

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->getString() => "http://www.web.cz/root/aaa/bbb/a.html"
```

```
$url->getHost() => "www.web.cz"
$url->getHost("string") => "www.web.cz"
$url->getHost("array") => [
	[0] => "www.web.cz"
]
```

```
$url->getPath() => [
	[0] => "ccc",
	[1] => "bbb",
	[2] => "a.html"
]
$url->getPath("string") => "ccc/bbb/a.html"
$url->getPath("array") => [
	[0] => "ccc",
	[1] => "bbb",
	[2] => "a.html"
]
```

getString()
-----------

[](#getstring)

get the whole URL in string format.

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->addPath("file");			// add PATH URL
$url->addQuery(["name" => "jerome"]);	// add Query in URL

$url->getString() => "http://www.web.cz/root/aaa/bbb/a/file.html?name=jerome"
```

---

getDepth()
----------

[](#getdepth)

return number of all folder from ROOT

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->getDepth() => 2

$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a");
$url->getDepth() => 3
```

linkRoot()
----------

[](#linkroot)

return path, which return this url to root

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->linkRoot() => "../../"

$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a");
$url->linkRoot() => "../../../"
```

---

addPath($add\_part)
-------------------

[](#addpathadd_part)

$add\_part \[string | array of strings\] add items to ROOT part.

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->addPath(["ccc", "ddd"]);
$url->getPath("string") => "aaa/bbb/a/ccc/ddd.html"
$url->getString() => "http://www.web.cz/root/aaa/bbb/a/ccc/ddd.html"

$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a");
$url->addPath(["ccc", "ddd"]);
$url->getPath("string") => "aaa/bbb/a/ccc/ddd"
$url->getString() => "http://www.web.cz/root/aaa/bbb/a/ccc/ddd"
```

beforePath($add\_part)
----------------------

[](#beforepathadd_part)

$add\_part \[string | array of strings\] add items to ROOT part.

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->beforePath(["ccc", "ddd"]);

$url->getPath("string") => "ccc/ddd/aaa/bbb/a.html"
$url->getString() => "http://www.web.cz/root/ccc/ddd/aaa/bbb/a.html"
```

addQuery($add\_part)
--------------------

[](#addqueryadd_part)

$add\_part \[key array\] add items to ROOT part.

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->addQuery(["name" => "jerome", "age=15"]);

$url->getQuery("string") => "?name=jerome&age=15"
$url->getString() => "http://www.web.cz/root/aaa/bbb/a.html?name=jerome&age=15"

$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html?member=me");
$url->addQuery(["name" => "jerome", "age=15"]);

$url->getQuery("string") => "?member=me&name=jerome&age=15"
$url->getString() => "http://www.web.cz/root/aaa/bbb/a.html?member=me&name=jerome&age=15"
```

---

hasExtension()
--------------

[](#hasextension)

return 1 if the URL is ending with file: ".../a.html"
return 0 if the URL is ending onn folder: ".../a"

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->hasExtension() => 1

$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a");
$url->hasExtension() => 0
```

getExtension()
--------------

[](#getextension)

Get extension of URL

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->getExtension() => "html"
```

removeExtension()
-----------------

[](#removeextension)

If URL has extension =&gt; ".html" it will remove it from path

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$extension = $url->removeExtension();

$url->getString() => "http://www.web.cz/root/aaa/bbb/a"
$extension => "html"
```

exist()
-------

[](#exist)

check if URL exist as File/Folder

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->exist() => 1
```

isFolder()
----------

[](#isfolder)

check if URL exist as Folder

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->isFolder() => 0
```

isFile()
--------

[](#isfile)

check if URL exist as File

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$url->isFile() => 1
```

---

remove...()
-----------

[](#remove)

$add\_part \[key array\] add items to ROOT part.

- **removeScheme()** - remove scheme part: "http"
- **removeHost()** - remove Host part: "web.cz"
- **removeRoot()** - remove Root part: \["aaa"\]
- **removePath()** - remove Path part: \["bbb", "a.html"\]
- **removeQuery()** - remove Query part: \["member" =&gt; "me", "age" =&gt; "15"\]
- **removeFragment()** - remove hastag part: "hashtag"

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html?member=me&age=15");
$remove_part = $url->removeScheme();

$url->getString() => "www.web.cz/root/aaa/bbb/a.html"
$remove_part => "http"
```

### removePath($path\_part)

[](#removepathpath_part)

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html");
$remove_part = $url->removePath(["aaa", "bbb"]);

$url->getString() => "www.web.cz/root/a.html"
$remove_part = [
	[0] => "aaa",
	[1] => "bbb"
]
```

### removeQuery($key\_array)

[](#removequerykey_array)

```
$url = new \UrlParser\Url("http://www.web.cz/root/aaa/bbb/a.html?member=me&age=15");
$remove_part = $url->removeQuery(["member"]);

$url->getString() => "www.web.cz/root/aaa/bbb/a.html?age=15"
$remove_part = [
	["member"] => "me"
]
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

13

Last Release

2204d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17721175?v=4)[Zerig](/maintainers/Zerig)[@Zerig](https://github.com/Zerig)

---

Top Contributors

[![Zerig](https://avatars.githubusercontent.com/u/17721175?v=4)](https://github.com/Zerig "Zerig (80 commits)")

---

Tags

urlurl-parser

### Embed Badge

![Health badge](/badges/zerig-url-parser/health.svg)

```
[![Health](https://phpackages.com/badges/zerig-url-parser/health.svg)](https://phpackages.com/packages/zerig-url-parser)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k789.4M1.8k](/packages/symfony-routing)[league/uri

URI manipulation library

1.1k206.4M277](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[spatie/url

Parse, build and manipulate URL's

73914.3M97](/packages/spatie-url)[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

48619.2M541](/packages/nette-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
