PHP產生短網址的3種方法代碼執行個體,php產生3種執行個體_PHP教程

來源:互聯網
上載者:User

PHP產生短網址的3種方法代碼執行個體,php產生3種執行個體


短網址服務,可能很多朋友都已經不再陌生,現在大部分微博、手機寄件提醒等地方已經有很多應用模式了,並佔據了一定的市場。估計很多朋友現在也正在使用。 看過新浪的短串連服務,發現後面主要有6個字串組成。

太多演算法的東西,也沒必要去探討太多,最主要的還是實現,下面是三種方法的代碼:

<?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/");  ?>


找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 "產生成功";
}
 

http://www.bkjia.com/PHPjc/840755.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/840755.htmlTechArticlePHP產生短網址的3種方法代碼執行個體,php產生3種執行個體 短網址服務,可能很多朋友都已經不再陌生,現在大部分微博、手機寄件提醒等地方已經...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.