codenamegary / url-parser
在保持所有部分完整性的同时解析、合并和修改URL。
0.1.5-beta
2013-11-15 21:12 UTC
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-09-28 13:40:46 UTC
README
PHP最佳URL工具!
#####特性
- 完全测试
- 链式方法
- PSR-0自动加载和PSR-1兼容
- 友好的语法,用于处理段、查询字符串和其他URL部分
#####即将推出
- 批量处理多个URL的包装器
- Composer / Packagist发布
###安装
- 解压到您选择的位置
- 包含url.php
- @include('path/to/extracted/files/src/codenamegary/urlparser/URL.php');
- 或者使用您选择的PSR-0兼容自动加载器
- 映射命名空间 "codenamegary" => 'path/to/extracted/files/src/codenamegary'
#####通过Composer通过Packagist
- 在composer.json中添加"codenamegary/url-parser": "0.1.5-beta"到require
###文档
- PHPDocs包含在repo下的'path/to/extracted/files/docs/index.html'
- 在整个源代码中有大量的文档和示例,在url.php
#使用示例
###加载一个复杂的URL并合并一些查询参数。
$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();
####返回
###加载一个复杂的URL并删除一些查询参数。
$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();
####返回
###获取当前访问页面的URL解析器实例
// .. and strip all the segments and query string from the URI $url = new codenamegary\urlparser\URL; $url->stripSegments() ->stripQueries() ->make(); echo $url;
####返回
当前页面的完整URL减去URI段和查询字符串。
###交换URI字符串
$url = new codenamegary\urlparser\URL('http://www.apple.com/bananas/coconut/date/elephant/giraffe'); $url->swapSegment('date','raisin'); echo $url->make();
####返回
http://www.apple.com/bananas/coconut/raisin/elephant/giraffe
###在coconut前面添加内容
$url = new codenamegary\urlparser\URL('http://www.apple.com/bananas/coconut/date/elephant/giraffe') ->prependSegment('lime','coconut'); echo $url->make();
####返回
http://www.apple.com/bananas/lime/coconut/date/elephant/giraffe
###使用方法链更改主机和协议
$url = codenamegary\urlparser\URL::to('http://www.apple.com/bananas/coconut/date/elephant/giraffe')->host('www.microsoft.com')->protocol('ftp'); echo $url->make();
####返回
ftp://www.microsoft.com/bananas/coconut/date/elephant/giraffe