'', '"'=>'', '`'=>'', '\\'=>'', '<'=>'<', '>'=>'>'); return strtr(trim($pStr), array_merge($tTrans, $pTrans)); } /** * 获得 KEY 对应的 数组值 * * @param array $pArr * @param str $pKey * @param str $pDefault */ static function arr2str($pArr, $pKey, $pDefault=''){ return isset($pArr[$pKey])? $pArr[$pKey]: $pDefault; } /** * ID 转为 图片文件路径 * @param int $pId * @return str */ static function id2path($pId){ $tPid = str_pad($pId, 9, 0, 0); return array(substr($tPid, 0, 3).'/'.substr($tPid, 3, 3).'/', substr($tPid, 6)); } /** * 格式化数字 * @param $pNum * @param int $pLen * @param int $pRule 规则 0:四舍五入, 1:全入, 2:全舍 * @return int | float */ static function format($pNum, $pLen = 2, $pRule = 0){ # 整数部分 $pNum = str_replace(array('e','E','+'), '.', $pNum); $pNum = floatval($pNum); $tInt = intval($pNum); # 无小数直接返回 if(!$tPos = strpos($pNum, '.')) return $tInt;#return $pNum; # 小数部分 $tNum = substr($pNum, $tPos+1); # 指定长度 $tReturn = (float)('0.'.substr($tNum, 0, $pLen)); # 四舍五入 if(((0 == $pRule) && (isset($tNum{$pLen}) && ($tNum{$pLen} > 4))) || ((1 == $pRule) && intval(substr($tNum, $pLen)))){ $tReturn = (float)bcadd($tReturn, (float)('0.'.str_pad('', $pLen-1, 0).'1'), $pLen); } return bcadd($tInt, $tReturn, $pLen); } /** * 生成key * 1 ybex转币 */ static function generate_key($type, $uid, $randstr='Ybc!1900#$@'){ if(!$type = intval($type)){ return FALSE; } $result = ''; switch($type){ case 1: $result = md5($randstr.$uid.'uid2'); break; default: break; } return $result; } }