artoodetoo / urly
最小可行性 URL 缩短类
v0.1.0
2016-12-28 22:44 UTC
Requires
- php: >=5.6
This package is auto-updated.
Last update: 2024-08-29 04:47:25 UTC
README
您想要像 tinyurl.com 那样编码 URL 吗?
这是一个为您的辅助工具。
特性
Urly 使用 PDO 接口存储 URL。只需参考您的现有连接。
可选地,您可以指定表名、编码基数和 XOR 掩码。
访问方法非常明显:使用 set($url)
和 get($key)
。
安装
使用 composer 安装
composer require artoodetoo/urly
所需表结构
CREATE TABLE `urly` ( `id` int(10) NOT NULL AUTO_INCREMENT, `url` varchar(1000) NOT NULL, PRIMARY KEY (`id`) )
基本用法
保存 URL 和编码后的键
$db = new \PDO( 'mysql:dbname=homestead;host=127.0.0.1;charset=utf8', 'homestead', 'secret' ); // Set 62 base to get alfa-numeric key in both cases and // some magic number to make key sequence be less predictable $shortener = new \R2\Utility\Urly($db, 'my_urly', 62, 990749); $key = $shortener->set('https:///test.txt'); echo 'http://go.to/'.$key."\n"; // Something like 'http://go.to/49Jz'
通过键获取 URL
echo $shortener->get('49Jz'); // Saved URL or empty string if not found
许可证
Urly 是开源软件,许可协议为 MIT 许可协议