1. Go to this page and download the library: Download haixin/surl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
haixin / surl example snippets
/********** 面向对象 **********/
use HaiXin\Surl\Facades\Surl;
$url = 'https://github.com/sunmingyang/surl';
$surl = Surl::url($url)
//->expires('2021-07-16 00:00:00') 可以设置过期时间
//->config($config) 可以传入config进行替换
->encode()
->save()
->toString();
print_r($surl); // OWKhm
/********** 面向过程 **********/
use function HaiXin\Surl\Helpers\surl_encode;
$surl = surl_encode($url); // 仅编码,不保存到数据库,返回短码
use function HaiXin\Surl\Helpers\surl_save;
$surl = surl_save($url); // 编码,保存到数据库,返回模型
use function HaiXin\Surl\Helpers\surl;
$surl = surl($url); // 编码,保存到数据库,返回完整地址
print_r($surl); // https:/localhost/s/OWKhm