codenamegary / url-parser
Parse, merge and modify URLs while maintaining integrity of all parts.
Installs: 4 109
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 3
Open Issues: 0
Language:JavaScript
Requires
- php: >=5.3.0
Requires (Dev)
- php: >=5.3.0
- phpdocumentor/phpdocumentor: dev-master
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-11-23 14:20:26 UTC
README
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 .gz .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" => '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
###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
###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
http://www.apple.com/bananas/coconut/raisin/elephant/giraffe
###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
###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