Rumah  >  Artikel  >  php教程  >  PHP生成短网址的3种方法代码实例,php生成3种实例

PHP生成短网址的3种方法代码实例,php生成3种实例

WBOY
WBOYasal
2016-06-13 09:29:13961semak imbas

PHP生成短网址的3种方法代码实例,php生成3种实例

短网址服务,可能很多朋友都已经不再陌生,现在大部分微博、手机邮件提醒等地方已经有很多应用模式了,并占据了一定的市场。估计很多朋友现在也正在使用。 看过新浪的短连接服务,发现后面主要有6个字符串组成。

太多算法的东西,也没必要去探讨太多,最主要的还是实现,下面是三种方法的代码:

<&#63;php 
 
//纯随机生成方法
function random($length, $pool = '') 
  { 
    $random = ''; 
 
    if (empty($pool)) { 
      $pool  = 'abcdefghkmnpqrstuvwxyz'; 
      $pool  .= '23456789'; 
    } 
 
    srand ((double)microtime()*1000000); 
 
    for($i = 0; $i < $length; $i++) 
    { 
      $random .= substr($pool,(rand()%(strlen ($pool))), 1); 
    } 
 
    return $random; 
  } 
 
 $a=random(6);
print_r($a);  
 
// 枚举生成方法
function shorturl($input) { 
 $base32 = array ( 
  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",  
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",  
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",  
"u", "v", "w", "x", "y", "z",  
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",  
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",  
 "U", "V", "W", "X", "Y", "Z"
  ); 
 
 $hex = md5($input); 
 $hexLen = strlen($hex); 
 $subHexLen = $hexLen / 8; 
 $output = array(); 
 
 for ($i = 0; $i < $subHexLen; $i++) { 
  $subHex = substr ($hex, $i * 8, 8); 
  $int = 0x3FFFFFFF & (1 * ('0x'.$subHex)); 
  $out = ''; 
 
  for ($j = 0; $j < 6; $j++) { 
   $val = 0x0000001F & $int; 
   $out .= $base32[$val]; 
   $int = $int >> 5; 
  } 
 
  $output[] = $out; 
 } 
 
 return $output; 
} 
$a=shorturl("http://www.bkjia.com");
print_r($a);
//62 位生成方法
 
function base62($x) 
 
{ 
 
$show= ''; 
 
 while($x> 0) { 
 
$s= $x% 62; 
 
if($s> 35) { 
 
$s= chr($s+61);       
 
} elseif($s> 9 && $s<=35) { 
 
$s= chr($s+ 55); 
 
} 
 
$show.= $s; 
 
 $x= floor($x/62); 
 
} 
 
return $show;   
 
} 
 
function urlShort($url) 
 
{ 
 
$url= crc32($url); 
 
$result= sprintf("%u", $url); 
 
return base62($result); 
 
 } 
 
echo urlShort("http://www.bkjia.com/"); 
 
&#63;>

找PHP代码自动生成工具?》

Hkvstore PHPMaker v4.1.0.2 英文正式版(PHP代码自动生成工具)

相关网址:
www.hkvstore.com/phpmaker/

安装序号:
序号产生器放至於keygen夹内

破解说明:

中文化说明:

内容说明:

PHP代码自动生成工具,一款在Windows平台上运行的基於MYSQL数据库自动生成PHP脚本
的软体。使用生成的PHP代码,你可以通过WEB网页对数据库的记录进行浏览、修改、查
询、添加和删除。利用它你只需几步就可以得到完整的PHP代码。清晰易懂的生成代码,
方便开发人员在其基础上二次开发。包含注册机。

英文说明:

PHPMaker is a powerful automation tool that can generate a full set of PHP
quickly from MySQL database. Using PHPMaker, you can instantly create Web
sites that allow users to view, edit, search, add and delete records on the
Web. PHPMaker is designed for high flexibility, numerous options enable you
to generate PHP applications that best suits your needs. The generated
codes are clean, straightforward and easy-to-customize. The PHP scripts can
be run on both Windows or Linux/Unix servers. PHPMaker can save you tons of
time and is suitable for both beginners and experienced develpers alike.

XYZ STUDIO 强力推荐!!!一定让你值回票价,保证错不了。
≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
XYZCD Studio(31.to/xyz,76.to/xyz) 目录编辑

最后,有句老话还是要再强调一次!XYZ制作的目录,仅仅只是帮助您试用/选购各
种应用软体之用,如果您觉得这些试用的软体真的对您工作上真正有帮助,敬请务
必要买原版软体,以支援作者或出版公司能再出版最好的软体!!! 为了您将来的后
续服务,更应该要购买原版的软体......余下全文>>
 

php 生成文件代码,帮忙看下,

你foreach后的{}应该把后面的内容都括进来
正确的是
$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2'));

foreach($con as $id=>$val){
$title=$val[0];
$content=$val[1];
$path=$id.'.htm';
$fp=fopen("tmp.htm","r"); //只读打开模板
$str=fread($fp,filesize("tmp.htm"));//读取模板中内容
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);//替换内容
fclose($fp);

$handle=fopen($path,"w"); //写入方式打开新闻路径
fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件
fclose($handle);
echo "生成成功";
}
 

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn