您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 的常用函数

2024/4/8 9:45:29发布18次查看
php 的常用函数 1) { // 多字节字符 $return .= %u . strtoupper(bin2hex(mb_convert_encoding($str, 'ucs-2', $encoding))); } else { $return .= % . strtoupper(bin2hex($str)); } } return $return;}/** * php 实现 js unescape函数 * @param [type] $str [description] * @return [type] [description] */function unescape($str) { $str = rawurldecode($str); preg_match_all(/(?:%u.{4})|.{4};|\d+;|.+/u,$str,$r); $ar = $r[0]; foreach($ar as $k=>$v) { if(substr($v,0,2) == %u){ $ar[$k] = iconv(ucs-2,utf-8//ignore,pack(h4,substr($v,-4))); } elseif(substr($v,0,3) == ) { $ar[$k] = iconv(ucs-2,utf-8,pack(h4,substr($v,3,-1))); } elseif(substr($v,0,2) == ) { echo substr($v,2,-1).; $ar[$k] = iconv(ucs-2,utf-8,pack(n,substr($v,2,-1))); } } return join(,$ar);}/** * 数字转人名币 * @param [type] $num [description] * @return [type] [description] */function num2rmb ($num) { $c1 = 零壹贰叁肆伍陆柒捌玖; $c2 = 分角元拾佰仟万拾佰仟亿; $num = round($num, 2); $num = $num * 100; if (strlen($num) > 10) { return oh,sorry,the number is too long!; } $i = 0; $c = ; while (1) { if ($i == 0) { $n = substr($num, strlen($num)-1, 1); } else { $n = $num % 10; } $p1 = substr($c1, 3 * $n, 3); $p2 = substr($c2, 3 * $i, 3); if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) { $c = $p1 . $p2 . $c; } else { $c = $p1 . $c; } $i = $i + 1; $num = $num / 10; $num = (int)$num; if ($num == 0) { break; } } $j = 0; $slen = strlen($c); while ($j $m = substr($c, $j, 6); if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') { $left = substr($c, 0, $j); $right = substr($c, $j + 3); $c = $left . $right; $j = $j-3; $slen = $slen-3; } $j = $j + 3; } if (substr($c, strlen($c)-3, 3) == '零') { $c = substr($c, 0, strlen($c)-3); } // if there is a '0' on the end , chop it out return $c . 整;}/** * 特殊的字符 * @param [type] $str [description] * @return [type] [description] */function makesemiangle($str) { $arr = array( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[', '】' => ']', '〖' => '[', '〗' => ']', '{' => '{', '}' => '}', '《' => ' '》' => '>', '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-', ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.', ';' => ';', '?' => '?', '!' => '!', '…' => '-', '‖' => '|', '”' => '', '“' => '', '’' => '`', '‘' => '`', '|' => '|', '〃' => '', ' ' => ' ','.' => '.'); return strtr($str, $arr);}/** * 下载 * @param [type] $filename [description] * @param string $dir [description] * @return [type] [description] */function downloads($filename,$dir='./'){ $filepath = $dir.$filename; if (!file_exists($filepath)){ header(content-type: text/html; charset=utf-8); echo file not found!; exit; } else { $file = fopen($filepath,r); header(content-type: application/octet-stream); header(accept-ranges: bytes); header(accept-length: .filesize($filepath)); header(content-disposition: attachment; filename=.$filename); echo fread($file, filesize($filepath)); fclose($file); }}/** * 创建一个目录树 * @param [type] $dir [description] * @param integer $mode [description] * @return [type] [description] */function mkdirs($dir, $mode = 0777) { if (!is_dir($dir)) { mkdirs(dirname($dir), $mode); return mkdir($dir, $mode); } return true;}
复制代码
1) { // 多字节字符 $return .= %u . strtoupper(bin2hex(mb_convert_encoding($str, 'ucs-2', $encoding))); } else { $return .= % . strtoupper(bin2hex($str)); } } return $return;}/** * php 实现 js unescape函数 * @param [type] $str [description] * @return [type] [description] */function unescape($str) { $str = rawurldecode($str); preg_match_all(/(?:%u.{4})|.{4};|\d+;|.+/u,$str,$r); $ar = $r[0]; foreach($ar as $k=>$v) { if(substr($v,0,2) == %u){ $ar[$k] = iconv(ucs-2,utf-8//ignore,pack(h4,substr($v,-4))); } elseif(substr($v,0,3) == ) { $ar[$k] = iconv(ucs-2,utf-8,pack(h4,substr($v,3,-1))); } elseif(substr($v,0,2) == ) { echo substr($v,2,-1).; $ar[$k] = iconv(ucs-2,utf-8,pack(n,substr($v,2,-1))); } } return join(,$ar);}/** * 数字转人名币 * @param [type] $num [description] * @return [type] [description] */function num2rmb ($num) { $c1 = 零壹贰叁肆伍陆柒捌玖; $c2 = 分角元拾佰仟万拾佰仟亿; $num = round($num, 2); $num = $num * 100; if (strlen($num) > 10) { return oh,sorry,the number is too long!; } $i = 0; $c = ; while (1) { if ($i == 0) { $n = substr($num, strlen($num)-1, 1); } else { $n = $num % 10; } $p1 = substr($c1, 3 * $n, 3); $p2 = substr($c2, 3 * $i, 3); if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) { $c = $p1 . $p2 . $c; } else { $c = $p1 . $c; } $i = $i + 1; $num = $num / 10; $num = (int)$num; if ($num == 0) { break; } } $j = 0; $slen = strlen($c); while ($j $m = substr($c, $j, 6); if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') { $left = substr($c, 0, $j); $right = substr($c, $j + 3); $c = $left . $right; $j = $j-3; $slen = $slen-3; } $j = $j + 3; } if (substr($c, strlen($c)-3, 3) == '零') { $c = substr($c, 0, strlen($c)-3); } // if there is a '0' on the end , chop it out return $c . 整;}/** * 特殊的字符 * @param [type] $str [description] * @return [type] [description] */function makesemiangle($str) { $arr = array( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[', '】' => ']', '〖' => '[', '〗' => ']', '{' => '{', '}' => '}', '《' => ' '》' => '>', '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-', ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.', ';' => ';', '?' => '?', '!' => '!', '…' => '-', '‖' => '|', '”' => '', '“' => '', '’' => '`', '‘' => '`', '|' => '|', '〃' => '', ' ' => ' ','.' => '.'); return strtr($str, $arr);}/** * 下载 * @param [type] $filename [description] * @param string $dir [description] * @return [type] [description] */function downloads($filename,$dir='./'){ $filepath = $dir.$filename; if (!file_exists($filepath)){ header(content-type: text/html; charset=utf-8); echo file not found!; exit; } else { $file = fopen($filepath,r); header(content-type: application/octet-stream); header(accept-ranges: bytes); header(accept-length: .filesize($filepath)); header(content-disposition: attachment; filename=.$filename); echo fread($file, filesize($filepath)); fclose($file); }}/** * 创建一个目录树 * @param [type] $dir [description] * @param integer $mode [description] * @return [type] [description] */function mkdirs($dir, $mode = 0777) { if (!is_dir($dir)) { mkdirs(dirname($dir), $mode); return mkdir($dir, $mode); } return true;}
复制代码
#完善curl功能function xcurl($url,$ref=null,$post=array(),$ua=mozilla/5.0 (x11; linux x86_64; rv:2.2a1pre) gecko/20110324 firefox/4.2a1pre,$print=false) { $ch = curl_init(); curl_setopt($ch, curlopt_autoreferer, true); if(!empty($ref)) { curl_setopt($ch, curlopt_referer, $ref); } curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_followlocation, 1); curl_setopt($ch, curlopt_returntransfer, 1); if(!empty($ua)) { curl_setopt($ch, curlopt_useragent, $ua); } if(count($post) > 0){ curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $post); } $output = curl_exec($ch); curl_close($ch); if($print) { print($output); } else { return $output; }}
复制代码
/** * 根据一个时间戳得到详细信息 * @param [type] $time [时间戳] * @return [type] * @author [yangsheng@yahoo.com] */function getdateinfo($time){ $day_of_week_cn=array(日,一,二,三,四,五,六); //中文星期 $week_of_month_cn = array('','第1周','第2周','第3周','第4周','第5周','第6周');#本月第几周 $tendays= gettendays(date('j',$time)); #获得旬 $quarter = getquarter(date('n',$time),date('y',$time));# 获取季度 $dimdate = array( 'date_key' => strtotime(date('y-m-d',$time)), #日期时间戳 'date_day' => date('y-m-d',$time), #日期yyyy-mm-dd 'current_year' => date('y',$time),#数字年 'current_quarter' => $quarter['current_quarter'], #季度 'quarter_cn' =>$quarter['quarter_cn'], 'current_month' =>date('n',$time),#月 'month_cn' =>date('y-m',$time), #月份 'tenday_of_month' =>$tendays['tenday_of_month'],#数字旬 'tenday_cn' =>$tendays['tenday_cn'],#中文旬 'week_of_month' =>ceil(date('j',$time)/7), #本月第几周 'week_of_month_cn' =>$week_of_month_cn[ceil(date('j',$time)/7)],#中文当月第几周 'day_of_year' =>date('z',$time)+1, #年份中的第几天 'day_of_month' =>date('j',$time),#得到几号 'day_of_week' =>date('w',$time)>0 ? date('w',$time):7,#星期几 'day_of_week_cn' =>'星期'.$day_of_week_cn[date('w',$time)], ); return $dimdate;}/** * 获得日期是上中下旬 * @param [int] $j [几号] * @return [array] [description] * @author [yangsheng@yahoo.com] */function gettendays($j){ $j = intval($j); if($j 31){ return false;#不是日期 } $tendays = ceil($j/10); switch ($tendays) { case 1:#上旬 return array('tenday_of_month'=>1,'tenday_cn'=>'上旬',); break; case 2:#中旬 return array('tenday_of_month'=>2,'tenday_cn'=>'中旬',); break; default:#下旬 return array('tenday_of_month'=>3,'tenday_cn'=>'下旬',); break; } return false;}/** * 根据月份获得当前第几季度 * @param [int] $n [月份] * @param [int] $y [年] * @return [array] [description] */function getquarter($n,$y=null){ $n = intval($n); if($n 12){ return false; #不是月份 } $quarter = ceil($n/3); switch ($quarter) { case 1: #第一季度 return array('current_quarter' => 1, 'quarter_cn'=>$y?$y.'-q1':'q1'); break; case 2: #第二季度 return array('current_quarter' => 2, 'quarter_cn'=>$y?$y.'-q2':'q2'); break; case 3: #第三季度 return array('current_quarter' => 3, 'quarter_cn'=>$y?$y.'-q3':'q3'); break; case 4: #第四季度 return array('current_quarter' => 4, 'quarter_cn'=>$y?$y.'-q4':'q4'); break; } return false;}
复制代码
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product