一個php短網(wǎng)址的生成代碼(仿微博短網(wǎng)址)
更新時間:2014年05月07日 10:48:24 作者:
這篇文章主要介紹了一個php短網(wǎng)址的生成代碼(仿微博短網(wǎng)址),需要的朋友可以參考下
分享一個php短網(wǎng)址的生成代碼。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>urlShort</title>
</head>
<body>
<form action="urlShort.php" method="post">
<input type="text" size="16" name="url" value="輸入網(wǎng)址" onfocus="if(this.value=='輸入網(wǎng)址'){this.value='';}" onblur="if(this.value==''){this.value='輸入網(wǎng)址'};">
<input type="submit" value=" 生成 " />
</form>
</body>
</html>
<?php
header("Content-Type:text/html;charset=UTF-8");
function base62($x){
$show = '';
while($x>0){
$s = $x % 62;
if ($s > 35){
$s = chr($s + 61);
}else if ($s > 5 && $S<=35){
$s = chr($s + 55);
} chabaoo.cn
$show .= $s;
$x = floor($x/62);
}
return $show;
}
//生成短網(wǎng)址
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo ("生成短網(wǎng)址為:<a href='http://$_POST[url]'>".url_short($_POST['url'])."</a>");
復制代碼 代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>urlShort</title>
</head>
<body>
<form action="urlShort.php" method="post">
<input type="text" size="16" name="url" value="輸入網(wǎng)址" onfocus="if(this.value=='輸入網(wǎng)址'){this.value='';}" onblur="if(this.value==''){this.value='輸入網(wǎng)址'};">
<input type="submit" value=" 生成 " />
</form>
</body>
</html>
<?php
header("Content-Type:text/html;charset=UTF-8");
function base62($x){
$show = '';
while($x>0){
$s = $x % 62;
if ($s > 35){
$s = chr($s + 61);
}else if ($s > 5 && $S<=35){
$s = chr($s + 55);
} chabaoo.cn
$show .= $s;
$x = floor($x/62);
}
return $show;
}
//生成短網(wǎng)址
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo ("生成短網(wǎng)址為:<a href='http://$_POST[url]'>".url_short($_POST['url'])."</a>");
您可能感興趣的文章:
- PHP生成短網(wǎng)址的3種方法代碼實例
- php簡單實現(xiàn)短網(wǎng)址(短鏈)還原的方法(測試可用)
- PHP生成短網(wǎng)址方法匯總
- PHP將URL轉(zhuǎn)換成短網(wǎng)址的算法分享
- PHP長網(wǎng)址與短網(wǎng)址的實現(xiàn)方法
- php生成短網(wǎng)址示例
- PHP通過調(diào)用新浪API生成t.cn格式短網(wǎng)址鏈接的方法詳解
- PHP生成短網(wǎng)址的思路以及實現(xiàn)方法的詳解
- PHP利用DWZ.CN服務生成短網(wǎng)址
- php 短鏈接算法收集與分析
- php調(diào)用新浪短鏈接API的方法
- php生成短網(wǎng)址/短鏈接原理和用法實例分析
相關(guān)文章
PHP PDO函數(shù)庫(PDO Functions)
PDO是一個“數(shù)據(jù)庫訪問抽象層”,作用是統(tǒng)一各種數(shù)據(jù)庫的訪問接口,與mysql和mysqli的函數(shù)庫相比,PDO讓跨數(shù)據(jù)庫的使用更具有親和力.2009-07-07php采用file_get_contents代替使用curl實例
這篇文章主要介紹了php采用file_get_contents代替使用curl的方法,實例講述了file_get_contents模擬curl的post方法,對于服務器不支持curl的情況來說有一定的借鑒價值,需要的朋友可以參考下2014-11-11PHP計算當前坐標3公里內(nèi)4個角落的最大最小經(jīng)緯度實例
這篇文章主要介紹了PHP計算當前坐標3公里內(nèi)4個角落的最大最小經(jīng)緯度的方法,涉及PHP數(shù)學運算的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-02-02