/** * 格式化金额 */ function format_amount($float) { if ($float == intval($float)) { return intval($float); } elseif ($float == sprintf('%.1f', $float)) { return sprintf('%.1f', $float); } return $float; }
/** * 判断是否是json */ function is_json($str) { if (is_string($str)) { $json = json_decode($str, true); if (is_array($json) || is_object($json)) { return true; } } return false; } //post function curlPost($url,$data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); return $output; } //异步post function asyncPost($url, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 1); // 设置超时为1秒 // 启动异步处理 curl_setopt($ch, CURLOPT_NOSIGNAL, 1); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // 执行请求,不等待响应 curl_exec($ch); // 关闭cURL资源,并且释放系统资源 curl_close($ch); }
//隐藏手机号中间四位 function hidePhoneNumber($phoneNumber) { // 确保输入的是有效的手机号(这里以11位手机号为例) if(strlen($phoneNumber) != 11) { return $phoneNumber; } // 保留前三位和后四位,隐藏其他数字 $hiddenNumber = substr($phoneNumber, 0, 3) . str_repeat('*', 4) . substr($phoneNumber, -4); return $hiddenNumber; }
//格式化文件大小 function formatFileSize($size): string { if ($size <= 0) return '0 B'; $units = array('B', 'KB', 'MB', 'GB', 'TB'); $factor = floor((strlen($size) - 1) / 3); return round($size / pow(1024, $factor), 2) . ' ' . $units[$factor]; }标签:常用,ch,return,函数,float,curl,php,CURLOPT,setopt From: https://blog.csdn.net/qq_39056048/article/details/140958707