短網址服務,可能很多朋友都已經不再陌生,現在大部分微博、手機郵件提醒等地方已經有很多應用模式了,並占據了一定的市場。估計很多朋友現在也正在使用。 看過新浪的短連接服務,發現後面主要有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/"); ?>
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制作的目錄,僅僅只是幫助您試用/選購各
種應用軟體之用,如果您覺得這些試用的軟體真的對您工作上真正有幫助,敬請務
必要買原版軟體,以支援作者或出版公司能再出版最好的軟體!!! 為了您將來的後
續服務,更應該要購買原版的軟體......余下全文>>
你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 "生成成功";
}