企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 应用公共返回方法 ``` function success($data = [], $count = 0) { header("Access-Control-Allow-Origin:*"); header('Access-Control-Allow-Methods:POST,GET'); header('Content-Type:application/json'); $list['code'] = 0; $list['msg'] = '操作成功'; $list['data'] = $data; $list['count'] = $count; echo json_encode($list); die; } function error($msg = 'error') { header("Access-Control-Allow-Origin:*"); header('Access-Control-Allow-Methods:POST,GET'); header('Content-Type:application/json'); $list['code'] = 1; $list['msg'] = $msg; echo json_encode($list); die; } function retMsg($code = 0,$msg = '', $data = [], $count = 0) { header("Access-Control-Allow-Origin:*"); header('Access-Control-Allow-Methods:POST,GET'); header('Content-Type:application/json'); $list['code'] = $code; $list['msg'] = $msg; $list['data'] = $data; $list['count'] = $count; echo json_encode($list); die; } ``` ### PHP采用超长(超大)数字运算防止数字以科学计数法显示的方法 ```php function calc($m,$n,$x){ $errors=array( '被除数不能为零', '负数没有平方根' ); switch($x){ case 'add': $t=bcadd($m,$n); break; case 'sub': $t=bcsub($m,$n); break; case 'mul': $t=bcmul($m,$n); break; case 'div': if($n!=0){ $t=bcdiv($m,$n); }else{ return $errors[0]; } break; case 'pow': $t=bcpow($m,$n); break; case 'mod': if($n!=0){ $t=bcmod($m,$n); }else{ return $errors[0]; } break; case 'sqrt': if($m>=0){ $t=bcsqrt($m); }else{ return $errors[1]; } break; } $t=preg_replace("/\..*0+$/",'',$t); return $t; } ``` ### 截取第一个斜杠后面的内容可以这样来 ```php $postfix = trim(strrchr($file_name, '.'),''); ``` ### 打印日志 ```php file_put_contents('ss.txt','data:-->'.'0'.PHP_EOL,FILE_APPEND); ```