如何使用PHP实现短域名互转?下面的代码可以帮助你实现,非常简单,需要的朋友可以参考下
复制代码 代码如下:
/**
* 短域名生成&解析类
*/
class Build_URL {
private $mem;
private $base_url = 'http://xxx.com/';
公共函数 __construct() {
$mem_conf = array(
array(
'主机' => '192.168.10 .90',
'端口' => '11116' '端口' => '11117'
),
);
$this->mem = new Memcache();
foreach ($mem_conf as $v) {
$this->mem->addServer($v['host'], $v[' port']);
}
}
公共函数编码($url) {
$url = trim($url);
if(!preg_match("#^ [|https://|ftp://]#iS", $url)) {
返回 false;
}
$md5 = md5($url);
$aid = $ this->mem->get($md5);
if(!$aid) {
if(($aid = $this->mem->increment('auto_increment_id')) = == false) {
$this->mem->set('auto_increment_id', 10000);
$aid = $this->mem->increment('auto_increment_id');
}
$ this-> mem-> set($ md5,$ aiD);
} else {
$key = $this->dec2any($aid);
}
return $this->; base_url.$key;
}
公共函数解码($url) {
$key = str_replace($this->base_url, '', trim($url));
return $this->mem->get($key);
}
private function dec2any($num, $base=62, $index=false) {
$out = '';
如果 (! $base ) {
$base = strlen($index);
} else if (! $index ) {
$index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ",0,$base);
}
$t = ($num == 0) ? 0 : floor(log10($num) / log10($base));
for ($t; $t >= 0; $t--) {
$a = floor($num / pow( $base, $t ));
$out = $out . substr($index, $a, 1);
$num = $num - ($a * pow( $base, $t ));
}
return $out;
}
}
$app = new Build_URL();
$url = array(
'http://www.baidu.com',
'http://www.google.com',
'http://www.jb51.net'
);
foreach ($url as $v) {
$sort = $app->encode($v);
echo "sort link: ".$sort."n";
$original = $app->decode($sort);
echo "original: ".$original."n";
}
?>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3汉化版
中文版,非常好用

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具