mrferos / purl
此包的最新版本(dev-master)没有提供许可信息。
gruns 编写的 furl 库的 PHP 版本
dev-master
2013-11-04 13:04 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-06 09:31:48 UTC
README
将 furl Python 库无耻地移植到 PHP,以简化 URL 操作。
查询
操作 URL 查询非常简单
$url = \Purl\Purl::fromString('http://www.google.com/?one=1&two=2'); unset($url['one']); $url['three'] = 'foo'; echo $url->toString(); // http://www.google.com/?two=2&three=foo
或者你可以这样做
$url = \Purl\Purl::fromString('http://www.google.com/?one=1&two=2'); $url->getQuery()->add('three','foo') ->remove('one'); echo $url; // http://www.google.com/?two=2&three=foo
还有另外一种方法,因为 Purl 对象中的查询有简单的访问器方法
$url = \Purl\Purl::fromString('http://www.google.com/?one=1&two=2'); $url->add('three', 'foo') ->remove('one'); echo $url; // http://www.google.com/?two=2&three=foo
路径
你可以这样添加或从路径中删除
$url = \Purl\Purl::fromString('http://www.google.com/path/?foo=2'); $url->getPath()->add('second-part'); // 'http://www.google.com/path/second-part/?foo=2' $url->getPath()->remove('path'); // http://www.google.com/second-part/?foo=2
片段
可以像这样编辑片段
$url = \Purl\Purl::fromString('http://www.google.com/path/?foo=2#fragment/foo?arg=one'); $url->getFragment()->getQuery()->remove('arg'); // http://www.google.com/path/?foo=2#fragment/foo $url->getFragment()->getPath()->remove('foo'); // http://www.google.com/path/?foo=2#fragment