/** * 校验日期格式是否正确 * * @param string $date 日期 * @param string $formats 需要检验的格式数组 * @return boolean */ function isDate($date, $formats = ['Y-m-d', 'Y/m/d']) { $timestamp = strtotime($date); ...
<?php /** * 输出JSON * * @param mixed $data * @param bool $push (true: echo & die | false: return) */ function pushJson($data, $push = true) { if (version_compare(PHP_VERSION, '5.4.0...
/** * 对图片进行base64编码转换 * * @param string $image_file * @return string */ function base64EncodeImage($image_file) { $base64_image = ''; if (is_file($image_file)) { $image_info = ...
/** * 获取一个指定长度的随机字符串 * * @param int $len * @return string */ function getRandomString($len = 8) { $str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $strLen = str...
<?php /** * 获取客户端IP地址 * * @return NULL | string */ function getClientIp() { $ip = null; if ($ip !== null) { return $ip; } if (isset($_SERVER)) { if (isset($...
PHP截取指定字符前的字符串$str = 'A|B||C|D'; echo substr($str,0,strpos($str, '||')); 输出:A|B
//截取指定两个字符之间的字符串 public function cut($begin,$end,$str){ $b = mb_strpos($str,$begin) + mb_strlen($begin); $e = mb_strpos($str,$end) - $b; return mb_substr($str,$b,$e); }
<?php function strFilter($str){ //特殊字符的过滤方法 $str = str_replace('`', '', $str); $str = str_replace('·', '', $str); $str = str_replace('~', '', $str); $str = str_replace('!', '', $str); ...
Mysql类<?php/**Mysql类 */class Mysql{ private static $link = null;//数据库连接 /**私有的构造方法 */private function __construct(){} /**连接数据库@return obj 资源对象 */private static function conn(){if(self::$l...
<?php /** * 取得当前页面完整url */ function geturl() { $url = ''; if (isset ( $_SERVER ['REQUEST_URI'] )) { $url = $_SERVER ['REQUEST_URI']; } else { $url = $_SERVER ['Ph...