From 5e6f00de6996504189d74667970d60b6fa32bca9 Mon Sep 17 00:00:00 2001 From: "ZLW-PC\\Administrator" <374861669@qq.com> Date: Thu, 28 Mar 2019 17:17:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=BD=ACbase64=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Common/Helper.php | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/Common/Helper.php b/app/Common/Helper.php index 04d520c..faaca08 100644 --- a/app/Common/Helper.php +++ b/app/Common/Helper.php @@ -383,4 +383,50 @@ class Helper return ''; } + + /** + * 图片转base64 + * @param image_file String 图片路径 + * @return 转为base64的图片 + */ + public static function Base64EncodeImage($image_file) + { + if(file_exists($image_file) || is_file($image_file)) + { + $base64_image = ''; + $image_info = getimagesize($image_file); + $image_data = fread(fopen($image_file, 'r'), filesize($image_file)); + $base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data)); + return $base64_image; + } + + return false; + } + + //提取数字 + public static function findNum($str='') + { + $str=trim($str); + if(empty($str)){return '';} + $reg='/(\d{3}(\.\d+)?)/is';//匹配数字的正则表达式 + preg_match_all($reg,$str,$result); + if(is_array($result)&&!empty($result)&&!empty($result[1])&&!empty($result[1][0])){ + return $result[1][0]; + } + + return ''; + } + + /** + * 过滤emoji + */ + public static function filterEmoji($str) + { + // preg_replace_callback执行一个正则表达式搜索并且使用一个回调进行替换 + $str = preg_replace_callback('/./u', function (array $match) { + return strlen($match[0]) >= 4 ? '' : $match[0]; + }, $str); + + return $str; + } } \ No newline at end of file