jwage / Purl
Licence: mit
Purl is a simple Object Oriented URL manipulation library for PHP 7.2+
Stars: ✭ 884
Labels
Projects that are alternatives of or similar to Purl
Mnmlurl
🔗 Minimal URL - Modern URL shortener with support for custom alias & can be hosted even in GitHub pages [DEPRECATED]
Stars: ✭ 311 (-64.82%)
Mutual labels: url
Better Link Movement Method
Attempts to improve how clickable links are detected, highlighted and handled in TextView
Stars: ✭ 684 (-22.62%)
Mutual labels: url
Environmentswitcher
🔥No repackage, switch environment with one click.(无需重新打包,一键切换环境 )
Stars: ✭ 401 (-54.64%)
Mutual labels: url
React Native Hyperlink
A <Hyperlink /> component for react-native that makes urls, fuzzy links, emails etc clickable
Stars: ✭ 572 (-35.29%)
Mutual labels: url
Compass
🌍 Compass helps you setup a central navigation system for your application
Stars: ✭ 828 (-6.33%)
Mutual labels: url
Limax
Node.js module to generate URL slugs. Another one? This one cares about i18n and transliterates non-Latin scripts to conform to the RFC3986 standard. Mostly API-compatible with similar modules.
Stars: ✭ 423 (-52.15%)
Mutual labels: url
Urlembeddedview
URLEmbeddedView automatically caches the object that is confirmed the Open Graph Protocol.
Stars: ✭ 633 (-28.39%)
Mutual labels: url
Laravel Url Signer
Create and validate signed URLs with a limited lifetime
Stars: ✭ 611 (-30.88%)
Mutual labels: url
E2guardian
E2guardian is a web content filter that can work in proxy, transparent or icap server modes
Stars: ✭ 340 (-61.54%)
Mutual labels: url
Url Polyfill
Polyfill URL and URLSearchParams to match last ES7 specifications
Stars: ✭ 294 (-66.74%)
Mutual labels: url
Digger
Digger is a lightweight download framework that requires only one line of code to complete the file download task
Stars: ✭ 521 (-41.06%)
Mutual labels: url
Api
姬长信API For Docker 一个基于多种编程语言开源免费不限制提供生活常用,出行服务,开发工具,金融服务,通讯服务和公益大数据的平台.
Stars: ✭ 743 (-15.95%)
Mutual labels: url
Purl
Purl is a simple Object Oriented URL manipulation library for PHP 7.2+
Installation
The suggested installation method is via composer:
composer require jwage/purl
Using Purl
Creating Url instances is easy. You can specify the URL you want, or just use the current URL:
use Purl\Url;
$url = new Url('http://jwage.com');
$currentUrl = Url::fromCurrent();
You can chain methods together after creating the Url
like this:
$url = (new Url('http://jwage.com'))
->set('scheme', 'https')
->set('port', '443')
->set('user', 'jwage')
->set('pass', 'password')
->set('path', 'about/me')
->set('query', 'param1=value1¶m2=value2')
->set('fragment', 'about/me?param1=value1¶m2=value2');
echo $url->getUrl(); // https://jwage:[email protected]:443/about/me?param1=value1¶m2=value2#about/me?param1=value1¶m2=value2
// $url->path becomes instanceof Purl\Path
// $url->query becomes instanceof Purl\Query
// $url->fragment becomes instanceof Purl\Fragment
Path Manipulation
$url = new Url('http://jwage.com');
// add path segments one at a time
$url->path->add('about')->add('me');
// set the path data from a string
$url->path = 'about/me/another_segment'; // $url->path becomes instanceof Purl\Path
// get the path segments
print_r($url->path->getData()); // array('about', 'me', 'another_segment')
Query Manipulation
$url = new Url('http://jwage.com');
$url->query->set('param1', 'value1');
$url->query->set('param2', 'value2');
echo $url->query; // param1=value1¶m2=value2
echo $url; // http://jwage.com?param1=value1¶m2=value2
// set the query data from an array
$url->query->setData([
'param1' => 'value1',
'param2' => 'value2'
]);
// set the query data from a string
$url->query = 'param1=value1¶m2=value2'; // $url->query becomes instanceof Purl\Query
print_r($url->query->getData()); //array('param1' => 'value1', 'param2' => 'value2')
Fragment Manipulation
$url = new Url('http://jwage.com');
$url->fragment = 'about/me?param1=value1¶m2=value2'; // $url->fragment becomes instanceof Purl\Fragment
A Fragment is made of a path and a query and comes after the hashmark (#).
echo $url->fragment->path; // about/me
echo $url->fragment->query; // param1=value1¶m2=value2
echo $url; // http://jwage.com#about/me?param1=value1¶m2=value2
Extract URLs
You can easily extract urls from a string of text using the extract
method:
$string = 'some text http://google.com http://jwage.com';
$urls = Url::extract($string);
echo $urls[0]; // http://google.com/
echo $urls[1]; // http://jwage.com/
Join URLs
You can easily join two URLs together using Purl:
$url = new Url('http://jwage.com/about?param=value#fragment');
$url->join('http://about.me/jwage');
echo $url; // http://about.me/jwage?param=value#fragment
Or if you have another Url
object already:
$url1 = new Url('http://jwage.com/about?param=value#fragment');
$url2 = new Url('http://about.me/jwage');
$url1->join($url2);
echo $url1; // http://about.me/jwage?param=value#fragment
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].