[PHP]把長數字轉為短字??/a> [PHP]

來源:本網整理

哦,我只聽說過轉換成字符串的,字符型像樓上說的,會損失精度哦,要是轉換成字符串的話,可以用C提供的庫函數,比如:int i=11;char ch[3];itoa(i,ch,10);將整型轉換成字符型,i 為要轉換的整型數,ch為存放轉換后的字符串,10表示為10進制數,包含頭文件#include<stdlib.h>www.anxorj.tw防采集請勿采集本網。

比較長的數字字符串轉為短的字符字符串 scrolltotop.offset(100,120); scrolltotop.init();

[1].[代碼] [PHP]代碼 跳至[1]

/** * 將數字轉為短網址代碼 * * @param int $number 數字 * @return string 短網址代碼 */function generate_code($number) { $out = ""; $codes = "abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; while ($number > 60) { $key = bcmod($number,'61'); $number = bcsub(bcdiv($number,'61'),'1'); $out = $codes{$key}.$out; } return $codes{$number}.$out;}/** * 將短網址代碼轉為數字 * * @param string $code 短網址代碼 * @return int 數字 */function get_num($code){ $codes = "abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $num = 0; $i = strlen($code); for($j=0;$j<strlen($code);$j++){ $i--; $char = $code{$j}; $pos = strpos($codes,$char); $num = bcadd(bcmul(bcpow("61", $i),($pos + 1)),$num); } $num=bcsub($num,"1"); return $num;}/*****函數結束****/$id="1973337397412392446";echo $id."<br/>";$did=generate_code($id);echo generate_code($id)."<br/>";echo get_num($did); SyntaxHighlighter.autoloader( 'applescript/js/sh309/scripts/shBrushAppleScript.js?t=1451961936000', 'actionscript3 as3/js/sh309/scripts/shBrushAS3.js?t=1451961936000', 'bash shell/js/sh309/scripts/shBrushBash.js?t=1451961936000', 'coldfusion cf/js/sh309/scripts/shBrushColdFusion.js?t=1451961936000', 'cpp c/js/sh309/scripts/shBrushCpp.js?t=1451961936000', 'obj-c objc/js/sh309/scripts/shBrushObjC.js?t=1451961936000', 'c# c-sharp csharp/js/sh309/scripts/shBrushCSharp.js?t=1451961936000', 'css/js/sh309/scripts/shBrushCss.js?t=1451961936000', 'delphi pascal/js/sh309/scripts/shBrushDelphi.js?t=1451961936000', 'diff patch pas/js/sh309/scripts/shBrushDiff.js?t=1451961936000', 'erl erlang/js/sh309/scripts/shBrushErlang.js?t=1451961936000', 'groovy/js/sh309/scripts/shBrushGroovy.js?t=1451961936000', 'haxe hx/js/sh309/scripts/shBrushHaxe.js?t=1451961936000', 'java/js/sh309/scripts/shBrushJava.js?t=1451961936000', 'jfx javafx/js/sh309/scripts/shBrushJavaFX.js?t=1451961936000', 'js jscript javascript/js/sh309/scripts/shBrushJScript.js?t=1451961936000', 'perl pl/js/sh309/scripts/shBrushPerl.js?t=1451961936000', 'php/js/sh309/scripts/shBrushPhp.js?t=1451961936000', 'text plain/js/sh309/scripts/shBrushPlain.js?t=1451961936000', 'py python/js/sh309/scripts/shBrushPython.js?t=1451961936000', 'ruby rails ror rb/js/sh309/scripts/shBrushRuby.js?t=1451961936000', 'scala/js/sh309/scripts/shBrushScala.js?t=1451961936000', 'sql/js/sh309/scripts/shBrushSql.js?t=1451961936000', 'vb vbnet/js/sh309/scripts/shBrushVb.js?t=1451961936000', 'xml xhtml xslt html/js/sh309/scripts/shBrushXml.js?t=1451961936000' ); SyntaxHighlighter.all();

公元3世紀,古印度的一位科學家巴格達發明了阿拉伯數字。最古的計數目大概至多到3,為了要設想“4”這個數字,就必須把2和2加起來,5是2加2加1,3這個數字是2加1得來的,大概較晚才出現了用手寫

/*友好日期時間param DateTime$datetime 日期時間param int$size 精確到位數throws InvalidArgumentExceptionreturn stringfunction friendly_date($datetime,$size=1){if(is_int($datetime)){datetime=new DateTime($datetime);}if!($datetime instanceof DateTime)){throw new InvalidArgumentException('invalid"DateTime"object');}now=new DateTime();interval=$now->diff($datetime);intervalData=arrayinterval->y,$interval->m,$interval->d,interval->h,$interval->i,$interval->s,intervalFormat=array('年','個月e68a84e8a2ad7a686964616f31333335333731','天','小時','分種','秒');foreach($intervalData as$index=>$value){if($value){intervalData[$index]=$value.$intervalFormat[$index];} else {unset($intervalData[$index]);unset($intervalFormat[$index]);}}return implode('',array_slice($intervalData,0,$size));}內容來自www.anxorj.tw請勿采集。

免責聲明 - 關于我們 - 聯系我們 - 廣告聯系 - 友情鏈接 - 幫助中心 - 頻道導航
Copyright © 2017 www.anxorj.tw All Rights Reserved
陕西快乐10分下载