php 计算几分钟前、几小时前、几天前、几月前、几年前

php 计算几分钟前、几小时前、几天前、几月前、几年前

/** * 计算几分钟前、几小时前、几天前、几月前、几年前。 * $agoTime string Unix时间 * @author tangxinzhuan * @version 2016-10-28 */ function smartDate($agoTime) { $agoTime = (int)$agoTime; // 计算出当前日期时间到之前的日期时间的毫秒数,以便进行下一步的计算 $time = time() - $agoTime; if ($time >= 31104000) { // N年前 ...

PHP 2020-02-18 PM 3382℃ 0条
php 页面跳转

php 页面跳转

/** * 页面跳转 */ function emDirect($directUrl) { header("Location: $directUrl"); exit; }

PHP 2020-02-18 PM 3088℃ 0条
php删除文件或目录

php删除文件或目录

/** * 删除文件或目录 */ function emDeleteFile($file) { if (empty($file)) return false; if (@is_file($file)) return @unlink($file); $ret = true; if ($handle = @opendir($file)) { while ($filename = @readdir($handle)) { if ($filename == '.' || $filename...

PHP 2020-02-18 PM 3008℃ 0条
php生成一个随机的字符串

php生成一个随机的字符串

/** * 生成一个随机的字符串 * * @param int $length * @param boolean $special_chars * @return string */ function getRandStr($length = 12, $special_chars = true) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()';...

PHP 2020-02-18 PM 2693℃ 0条
php获取文件名后缀

php获取文件名后缀

/** * 获取文件名后缀 */ function getFileSuffix($fileName) { return strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); }

PHP 2020-02-18 PM 2837℃ 0条
php转换附件大小单位

php转换附件大小单位

/** * 转换附件大小单位 * * @param string $fileSize 文件大小 kb */ function changeFileSize($fileSize) { if ($fileSize >= 1073741824) { $fileSize = round($fileSize / 1073741824, 2) . 'GB'; } elseif ($fileSize >= 1048576) { $fileSize = round($fileSize / 1048576, 2) . 'MB'; ...

PHP 2020-02-18 PM 2337℃ 0条
PHP截取编码为utf8的字符串

PHP截取编码为utf8的字符串

/**截取编码为utf8的字符串 *@param string $strings 预处理字符串@param int $start 开始处 eg:0@param int $length 截取长度 */function subString($strings, $start, $length) {if (function_exists('mb_substr') && function_exists('mb_strlen')) { $sub_str = mb_substr($strings, $start, $length, 'utf8'); return mb_...

公告 2020-02-18 PM 2754℃ 0条
php验证email地址格式

php验证email地址格式

/** * 验证email地址格式 */ function checkMail($email) { if (preg_match("/^[\w\.\-]+@\w+([\.\-]\w+)*\.\w+$/", $email) && strlen($email) <= 60) { return true; } else { return false; } }

PHP 2020-02-18 PM 3633℃ 0条
PHP检测是否为IP

PHP检测是否为IP

/** * 检测是否为IP * @param [type] $ip [description] * @return [type] [description] */ function funip($ip){ //IP正则匹配 //0.0.0.0--- 255.255.255.255 $pat = "/^(((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))$/"; if(preg_match($pat,$ip)){ $...

PHP 2020-02-18 PM 2712℃ 0条
php转换HTML代码函数

php转换HTML代码函数

/** * 转换HTML代码函数 * * @param unknown_type $content * @param unknown_type $wrap 是否换行 */ function htmlClean($content, $nl2br = true) { $content = htmlspecialchars($content, ENT_QUOTES, 'UTF-8'); if ($nl2br) { $content = nl2br($content); } $content = str_replace(' ', '&a...

PHP 2020-02-18 PM 2217℃ 0条
PHP递归去除转义字符

PHP递归去除转义字符

/** * 递归去除转义字符 */ function stripslashesDeep($value) { $value = is_array($value) ? array_map('stripslashesDeep', $value) : stripslashes($value); return $value; }

PHP 2020-02-18 PM 2969℃ 0条