2017 © Pedro Peláez
 

library url-parser

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

image

codenamegary/url-parser

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

  • Thursday, October 2, 2014
  • by codenamegary
  • Repository
  • 2 Watchers
  • 5 Stars
  • 2,691 Installations
  • JavaScript
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

urlparser - 0.1.5 - BETA

Build Status, (*1)

The best little URL tool for PHP!, (*2)

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 .gz .bz2 ), (*3)

  • 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" => '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

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&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, (*4)

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&daddr=Toronto,+ON&hl=en&sll=43.653226,-79.383184&sspn=0.444641,1.056747&oq=tokyo&mra=ls&t=m&z=3, (*5)

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., (*6)

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

http://www.apple.com/bananas/coconut/raisin/elephant/giraffe, (*7)

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

http://www.apple.com/bananas/lime/coconut/date/elephant/giraffe, (*8)

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, (*9)

The Versions

02/10 2014

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar codenamegary

url parsing codenamegary

15/11 2013

dev-dev

dev-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Gary Saunders

url parsing codenamegary

15/11 2013

0.1.5-beta

0.1.5.0-beta

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Gary Saunders

url parsing codenamegary

02/04 2013

0.1.3-beta

0.1.3.0-beta

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Gary Saunders

url parsing codenamegary

02/04 2013

0.1.2-alpha

0.1.2.0-alpha

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Gary Saunders

url parsing codenamegary

02/04 2013

0.1.1-alpha

0.1.1.0-alpha

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Gary Saunders

url parsing codenamegary