PHPackages                             codenamegary/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. codenamegary/url-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

codenamegary/url-parser
=======================

Parse, merge and modify URLs while maintaining integrity of all parts.

0.1.5-beta(12y ago)44.2k3MITJavaScriptPHP &gt;=5.3.0

Since Apr 2Pushed 8y ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (6)Used By (0)

urlparser - 0.1.5 - BETA
------------------------

[](#urlparser---015---beta)

[![Build Status](https://camo.githubusercontent.com/b034f4ece2b884264a7fac1e23281b0ac12020c33bd79d7a9f5d8edad88203ac/68747470733a2f2f7472617669732d63692e6f72672f636f64656e616d65676172792f75726c2d7061727365722e706e673f6272616e63683d302e312e352d62657461)](https://travis-ci.org/codenamegary/url-parser)

The best little URL tool for PHP!

\#####Features

- Fully tested
- Chainable methods
- PSR-0 autoload and PSR-1 compliant
- Friendly syntax for Segment, Query String and other URL part manipulation

\#####Coming Soon

- Batch wrapper for processing multiple URLs
- Composer / Packagist publishing

\###Installation

\#####Manually Download the Master ( [.zip](https://bitbucket.org/codenamegary/urlparser/get/master.zip) [.gz](https://bitbucket.org/codenamegary/urlparser/get/master.tar.gz) [.bz2](https://bitbucket.org/codenamegary/urlparser/get/master.tar.bz2) )

- Extract to the location of your choosing
- Include url.php
- @include('path/to/extracted/files/src/codenamegary/urlparser/URL.php');
- **OR** use a PSR-0 compatible Autoloader of your choice
- Map namespace "codenamegary" =&gt; 'path/to/extracted/files/src/codenamegary'

\#####Composer via Packagist

- In composer.json add "codenamegary/url-parser": "0.1.5-beta" to require

\###Docs

- PHPDocs are included in the repo under 'path/to/extracted/files/docs/index.html'
- Plenty of documentation and examples throughout the source in [url.php](https://bitbucket.org/codenamegary/url-parser/src/b35343be3583178d870e2e7ebc0d9b6120d7ca2a/src/codenamegary/urlparser/URL.php?at=master)

\#Usage Examples

\###Load a complex URL and merge in some query parameters.

```
$url = new codenamegary\urlparser\URL('https://maps.google.ca/maps?saddr=Tokyo,+Japan&daddr=Toronto,+ON&hl=en&sll=43.653226,-79.383184&sspn=0.444641,1.056747&geocode=FRCUIAIduoZTCCnnVy7whxtdYDGJG1cii2EBLg%3BFWoYmgIdcLVE-ymlO8bXkMvUiTF3xLQqUFU1Mg&oq=tokyo&mra=ls&t=m&z=3');
$url->addQuery(array(
	'foo'	=> 'bar',
));
echo $url->make();
```

\####Returns

[https://maps.google.ca/maps?saddr=Tokyo,+Japan&amp;daddr=Toronto,+ON&amp;hl=en&amp;sll=43.653226,-79.383184&amp;sspn=0.444641,1.056747&amp;geocode=FRCUIAIduoZTCCnnVy7whxtdYDGJG1cii2EBLg%3BFWoYmgIdcLVE-ymlO8bXkMvUiTF3xLQqUFU1Mg&amp;oq=tokyo&amp;mra=ls&amp;t=m&amp;z=3&amp;foo=bar](https://maps.google.ca/maps?saddr=Tokyo,+Japan&daddr=Toronto,+ON&hl=en&sll=43.653226,-79.383184&sspn=0.444641,1.056747&geocode=FRCUIAIduoZTCCnnVy7whxtdYDGJG1cii2EBLg%3BFWoYmgIdcLVE-ymlO8bXkMvUiTF3xLQqUFU1Mg&oq=tokyo&mra=ls&t=m&z=3&foo=bar)

\###Load a complex URL and get rid of some query parameters.

```
$url = new codenamegary\urlparser\URL('https://maps.google.ca/maps?saddr=Tokyo,+Japan&daddr=Toronto,+ON&hl=en&sll=43.653226,-79.383184&sspn=0.444641,1.056747&geocode=FRCUIAIduoZTCCnnVy7whxtdYDGJG1cii2EBLg%3BFWoYmgIdcLVE-ymlO8bXkMvUiTF3xLQqUFU1Mg&oq=tokyo&mra=ls&t=m&z=3');
$url->stripQuery('geocode');
echo $url->make();
```

\####Returns

[https://maps.google.ca/maps?saddr=Tokyo,+Japan&amp;daddr=Toronto,+ON&amp;hl=en&amp;sll=43.653226,-79.383184&amp;sspn=0.444641,1.056747&amp;oq=tokyo&amp;mra=ls&amp;t=m&amp;z=3](https://maps.google.ca/maps?saddr=Tokyo,+Japan&daddr=Toronto,+ON&hl=en&sll=43.653226,-79.383184&sspn=0.444641,1.056747&oq=tokyo&mra=ls&t=m&z=3)

\###Get an instance of the URL parser for the page currently being visited

```
// .. and strip all the segments and query string from the URI
$url = new codenamegary\urlparser\URL;
$url->stripSegments()
    ->stripQueries()
    ->make();
echo $url;
```

\####Returns

Full URL of the current page minus the URI segments and query string.

\###Swap a URI string

```
$url = new codenamegary\urlparser\URL('http://www.apple.com/bananas/coconut/date/elephant/giraffe');
$url->swapSegment('date','raisin');
echo $url->make();
```

\####Returns

\###Put something in front of coconut

```
$url = new codenamegary\urlparser\URL('http://www.apple.com/bananas/coconut/date/elephant/giraffe')
    ->prependSegment('lime','coconut');
echo $url->make();
```

\####Returns

\###Change the host and protocol using method chaining

```
$url = codenamegary\urlparser\URL::to('http://www.apple.com/bananas/coconut/date/elephant/giraffe')->host('www.microsoft.com')->protocol('ftp');
echo $url->make();
```

\####Returns

ftp://www.microsoft.com/bananas/coconut/date/elephant/giraffe

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.8% 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 ~76 days

Total

4

Last Release

4610d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1509951?v=4)[Gary Saunders](/maintainers/codenamegary)[@codenamegary](https://github.com/codenamegary)

---

Top Contributors

[![codenamegary](https://avatars.githubusercontent.com/u/1509951?v=4)](https://github.com/codenamegary "codenamegary (45 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")

---

Tags

urlparsingcodenamegary

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jakubledl/dissect

Lexing and parsing in pure PHP

2234.7M11](/packages/jakubledl-dissect)[parsica-php/parsica

The easiest way to build robust parsers in PHP.

412171.6k4](/packages/parsica-php-parsica)[vstelmakh/url-highlight

Library to parse urls from string input

102923.8k12](/packages/vstelmakh-url-highlight)[jejik/mt940

An MT940 bank statement parser for PHP

881.2M2](/packages/jejik-mt940)[kingsquare/php-mt940

Simple MT940 parser in PHP

106827.7k3](/packages/kingsquare-php-mt940)[denissimon/formula-parser

Parsing and evaluating mathematical formulas given as strings.

80326.3k3](/packages/denissimon-formula-parser)

PHPackages © 2026

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