/** * 对图片进行base64编码转换 * * @param string $image_file * @return string */ function base64EncodeImage($image_file) { $base64_image = ''; if (is_file($image_file)) { $image_info = getimagesize($image_file); $image_data = fread(fopen($image_file, 'r'), filesize($image_file...
/** * 获取一个指定长度的随机字符串 * * @param int $len * @return string */ function getRandomString($len = 8) { $str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $strLen = strlen($str); $randomString = ''; if (! is_int($len) || $len <= 0) $len = 8; for...
<?php /** * 获取客户端IP地址 * * @return NULL | string */ function getClientIp() { $ip = null; if ($ip !== null) { return $ip; } if (isset($_SERVER)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']...
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); $str = str_replace('!', '', $str); $str = str_replace('@', '', $str); $str = str_replace('#', ...
Mysql类<?php/**Mysql类 */class Mysql{ private static $link = null;//数据库连接 /**私有的构造方法 */private function __construct(){} /**连接数据库@return obj 资源对象 */private static function conn(){if(self::$link === null){ $cfg = require './config.php'; self::$link = new Mysqli($cfg['host'],$cfg['user']...
<?php /** * 取得当前页面完整url */ function geturl() { $url = ''; if (isset ( $_SERVER ['REQUEST_URI'] )) { $url = $_SERVER ['REQUEST_URI']; } else { $url = $_SERVER ['Php_SELF']; $url .= empty ( $_SERVER ['QUERY_STRING'] ) ? '' : '?' . $_SERVER ['QUERY_STRING']; ...
<?php /** * 助手类 * @author www.shouce.ren * */ class Helper { /** * 判断当前服务器系统 * @return string */ public static function getOS(){ if(PATH_SEPARATOR == ':'){ return 'Linux'; }else{ return 'Windows'; } } /** * 当前微妙数 * @return number */ public static function microtime_float() { list ( $usec, ...
<?php /** * 判断当前服务器系统 * @return string */ function getOS(){ if(PATH_SEPARATOR == ':'){ return 'Linux'; }else{ return 'Windows'; } } echo getOS(); ?>
<?php header("Content-Type:text/html;charset=utf-8"); class PdoMysql{ public static $config = array();//设置连接参数,配置信息 public static $link = null;//保存连接标识符 public static $pconnect = false;//是否开启长连接 public static $dbVersion = null;//保存数据库版本 public static $connected = false;//判断...