常用函数
-
获取网络图片的宽度和高度
// 获取网络图片的宽度和高度if (!function_exists('widht_gt_height')) { function widht_gt_height($webImage) { // 获取图片信息 $imageInfo = @getimagesize($webImage); // 检查是否成功获取图片信息 if ($imageInfo === false) { return true; } // 提取图片宽度和高度 $width = 0; if (isset($imageInfo[0]) && !empty($imageInfo[0])) { $width = $
-
将网络图片保存到指定的目录下
/** * 将网络图片保存到指定的目录下 * param $url 网络图片地址,例如:http://example.com/image.jpg * param $savePath 保存的图片路径,例如:/path/to/save/image.jpg*/if(!function_exists('save_image_from_url')) { function save_image_from_url($url, $savePath) { // 获取远程图片内容 $imageContent = file_get_contents($url); if ($imageContent === fals
-
生成一个随机的图片名
/** * 生成一个随机的图片名 * param $type 文件名的后缀 */if(!function_exists('get_image_file_name')) { function get_image_file_name($type = 'png') { if (in_array($type, ['png', 'jpg', 'jpeg'])) { return time().rand(1,99999).'.'.$type; } return ''; }}
-
把字符串中第一个出现的子字符串替换成指定的内容
/** * 把字符串中第一个出现的子字符串替换成指定的内容 * @param string $string 字符串 * @param string $substring 子字符串 * @param string $replacement 要替换的内容 */if(!function_exists('replace_first_sub_string')) { function replace_first_sub_string($string, $substring, $replacement) { $position = strpos($string, $substring); if ($posi
-
截取内容中指定字数的字符串
public function test(){ $text = "来源: Empower Labs\n“Rage Qu11<img src='http://bitscall.com/wp-content/uploads/2022/08/Z3Wr-t_3fs0.jpg' alt='Image'>11it”(“愤怒退出”),在11<img src='image.jpg' alt='Image'>11DAO领域被简称为“怒退”,曾是一个相对较小众的概念。随着DAO的发展,越来越多的DAO开始面临分叉、创始人出走、甚至清盘的状况,使得“愤怒退出”这一词汇逐渐频繁地出现
-
json返回函数
if (!function_exists('return_json')) { /** * json返回函数 * @param int $code 状态码 * @param string $msg 提示信息 * @param array $data 结果数据 * @return json 返回json数据 */ function return_json($code = 0, $msg = "操作成功", $data = []) { json(['code' => $code, 'msg' => $msg, 'data' => $data])->send(); die();