一個(gè)php短網(wǎng)址的生成代碼(仿微博短網(wǎng)址)
更新時(shí)間:2014年05月07日 10:48:24 作者:
這篇文章主要介紹了一個(gè)php短網(wǎng)址的生成代碼(仿微博短網(wǎng)址),需要的朋友可以參考下
分享一個(gè)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);
} www.dbjr.com.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>");
復(fù)制代碼 代碼如下:
<!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);
} www.dbjr.com.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種方法代碼實(shí)例
- php簡單實(shí)現(xiàn)短網(wǎng)址(短鏈)還原的方法(測試可用)
- PHP生成短網(wǎng)址方法匯總
- PHP將URL轉(zhuǎn)換成短網(wǎng)址的算法分享
- PHP長網(wǎng)址與短網(wǎng)址的實(shí)現(xiàn)方法
- php生成短網(wǎng)址示例
- PHP通過調(diào)用新浪API生成t.cn格式短網(wǎng)址鏈接的方法詳解
- PHP生成短網(wǎng)址的思路以及實(shí)現(xiàn)方法的詳解
- PHP利用DWZ.CN服務(wù)生成短網(wǎng)址
- php 短鏈接算法收集與分析
- php調(diào)用新浪短鏈接API的方法
- php生成短網(wǎng)址/短鏈接原理和用法實(shí)例分析
相關(guān)文章
PHP PDO函數(shù)庫(PDO Functions)
PDO是一個(gè)“數(shù)據(jù)庫訪問抽象層”,作用是統(tǒng)一各種數(shù)據(jù)庫的訪問接口,與mysql和mysqli的函數(shù)庫相比,PDO讓跨數(shù)據(jù)庫的使用更具有親和力.2009-07-07PHP與MongoDB簡介|安全|M+PHP應(yīng)用實(shí)例詳解
本篇文章是對(duì)PHP中的MongoDB簡介|安全|M+PHP應(yīng)用實(shí)例進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php采用file_get_contents代替使用curl實(shí)例
這篇文章主要介紹了php采用file_get_contents代替使用curl的方法,實(shí)例講述了file_get_contents模擬curl的post方法,對(duì)于服務(wù)器不支持curl的情況來說有一定的借鑒價(jià)值,需要的朋友可以參考下2014-11-11php初始化對(duì)象和析構(gòu)函數(shù)的簡單實(shí)例
本篇文章主要是對(duì)php初始化對(duì)象和析構(gòu)函數(shù)的簡單實(shí)例進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-03-03PHP計(jì)算當(dāng)前坐標(biāo)3公里內(nèi)4個(gè)角落的最大最小經(jīng)緯度實(shí)例
這篇文章主要介紹了PHP計(jì)算當(dāng)前坐標(biāo)3公里內(nèi)4個(gè)角落的最大最小經(jīng)緯度的方法,涉及PHP數(shù)學(xué)運(yùn)算的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-02-02