PHP code example of haixin / surl

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

use HaiXin\Surl\Facades\Surl;
$code = 'OWKhm'; 
$increment = true; // 每次解码,是否增加访问次数
$expires = true; // 失效是否允许访问

$url = Surl::decode($code, $increment, $expires); // 解码,返回原始地址
print_r($url); // https://github.com/sunmingyang/surl

use function HaiXin\Surl\Helpers\surl_decode;
$url = surl_decode($code); // 解码,返回原始地址
print_r($url); // https://github.com/sunmingyang/surl