<?php namespace TijsVerkoyen\CssToInlineStyles; use Symfony\Component\CssSelector\CssSelector; use Symfony\Component\CssSelector\CssSelectorConverter; use Symfony\Component\CssSelector\Exception\ExceptionInterface; use TijsVerkoyen\CssToInlineStyles\Css\Processor; use TijsVerkoyen\CssToInlineStyles\Css\Property\Processor as PropertyProcessor; use TijsVerkoyen\CssToInlineStyles\Css\Rule\Processor as RuleProcessor; use TijsVerkoyen\CssToInlineStyles\Css\Rule\Rule; class CssToInlineStyles { private $cssConverter; public function __construct() { if (class_exists('Symfony\Component\CssSelector\CssSelectorConverter')) { $this->cssConverter = new CssSelectorConverter(); } }这是一个邮件模板中的内联CSS库,需要的朋友可以下载使用
<?php /** * 参数处理类 * @author JasonWei */ class Params { public $get = array(); public $post = array(); function __construct() { if (!emptyempty($_GET)) { foreach ($_GET as $key => $val) { if (is_numeric($val)) { $this->get[$key] = $this->getInt($val); } else { $this->get[$key] = $this->getStr($val); } } } if (!emptyempty($_POST)) { foreach ($_POST as $key => $val) { if (is_numeric($val)) { $this->post[$key] = $this->getInt($val); } else { $this->post[$key] = $this->getStr($val); } } }这是一份很好用的PHP防注入类,需要的朋友可以下载使用
<?php /** * Validator 数据验证类 */ class Validator { /** * 待校验数据 * @var array */ private $_data; /** * 校验规则 * @var array */ private $_ruleList = null; /** * 校验结果 * @var bool */ private $_result = null; /** * 校验数据信息 * @var array */ private $_resultInfo = array(); /** * 构造函数 * @param array $data 待校验数据 */ public function __construct($data = null) { if ($data) { $this->_data = $data; } }这是一份功能很齐全的php验证类,需要的朋友可以下载使用
<?php class crypt { private $skey; public function __construct($key) { $this->skey = hash("md5", $key, true); //32位skey } public function safe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+', '/', '='), array('-', '_', ''), $data); return $data; } public function safe_b64decode($string) { $data = str_replace(array('-', '_'), array('+', '/'), $string); $mod4 = strlen($data) % 4; if ($mod4) { $data .= substr('====', $mod4); } return base64_decode($data); }这是一个PHP的加密解密类,需要的朋友可以下载使用
<?php class cls_http_request { public static function curl_get($url, $timeout = 1) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); $result = curl_exec($ch); curl_close($ch); if (is_string($result) && strlen($result)) { return $result; } else { return false; } }http请求处理类(基于CURL进行封装)get方式请求(curl)@param string $url 请求的url@param integer $timeout 超时时间(s)@return string(请求成功) | false(请求失败)
<?php class CacheLayer{ protected $root = ""; protected $cache = ""; protected $key = ""; protected $life = 0; public function __construct($key, $root = "/cachelayer"){ $this->root = $_SERVER["DOCUMENT_ROOT"].$root; $this->key = $key; } public function expired($life_span){ $this->life = $life_span; $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ $mtime = filemtime($file); return (time() >= ($mtime + $this->life)); }else{ return true; } } public function put($content){ $file = $this->root."/".$this->key.".cachelayer"; if(!is_dir(dirname($this->root))){ return false; } $this->delete(); $content = json_encode($content); return (bool)file_put_contents($file, $content); } public function get(){ $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ return json_decode(file_get_contents($file), true); } return array(); } public function delete(){ $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ unlink($file); return true; } return false; } } ?>这是一份很好用的PHP缓存类库,需要的朋友可以下载使用,可以通过文件缓存,大大缓解数据库的压力
<?php class upload { var $dir; //附件存放物理目录 var $time; //自定义文件上传时间 var $allow_types; //允许上传附件类型 var $field; //上传控件名称 var $maxsize; //最大允许文件大小,单位为KB var $thumb_width; //缩略图宽度 var $thumb_height; //缩略图高度 var $watermark_file; //水印图片地址 var $watermark_pos; //水印位置 var $watermark_trans;//水印透明度 //构造函数 //$types : 允许上传的文件类型 , $maxsize : 允许大小 , $field : 上传控件名称 , $time : 自定义上传时间 function upload($types = 'jpg|png', $maxsize = 1024, $field = 'attach', $time = '') { $this->allow_types = explode('|',$types); $this->maxsize = $maxsize * 1024; $this->field = $field; $this->time = $time ? $time : time(); } //设置并创建文件具体存放的目录 //$basedir : 基目录,必须为物理路径 //$filedir : 自定义子目录,可用参数{y}、{m}、{d} function set_dir($basedir,$filedir = '') { $dir = $basedir; !is_dir($dir) && @mkdir($dir,0777); if (!empty($filedir)) { $filedir = str_replace(array('{y}','{m}','{d}'),array(date('Y',$this->time),date('m',$this->time),date('d',$this->time)),strtolower($filedir));//用string_replace把{y} {m} {d}几个标签进行替换 $dirs = explode('/',$filedir); foreach ($dirs as $d) { !empty($d) && $dir .= $d.'/'; !is_dir($dir) && @mkdir($dir,0777); } } $th支持水印,日期,缩略图的php多文件上传类,设置并创建文件具体存放的目录,图片缩略图设置,如果不生成缩略图则不用设置,图片水印设置,如果不生成添加水印则不用设置,执行文件上传,处理完返回一个包含上传成功或失败的文件信息数组。
<?php class IP { public static function generate($province = '') { $ip_address = self::_IPSegment($province); $ip = self::_randomIP($ip_address['begin'], $ip_address['end']); return $ip; } public static function update() { require 'QueryList.class.php'; $province = array( 'BJ', 'GD', 'SD', 'ZJ', 'JS', 'SH', 'LN', 'SC', 'HA', 'HB', 'FJ', 'HN', 'HE', 'CQ', 'SX', 'JX', 'SN', 'AH', 'HL', 'GX', 'JL', 'YN', 'TJ', 'NM', 'XJ', 'GS', 'GZ', 'HI', 'NX', 'QH', 'XZ' ); $count = count($province); $ip_segment = array(); for ($i = 0; $i < $count; $i++) { // 采集IP地址段目标网址 $url = 'http://ips.chacuo.net/view/s_' . $province[$i]; $ip_list = QueryList::Query($url, array('begin' => array('.v_l', 'text'), 'end' => array('.v_r', 'text')), '', 'UTF-8'); $ip_array = $ip_list->jsonArr; $ip_segment[$province[$i]] = $ip_array; } $path = str_replace('\', '/', __DIR__); $file = $path . '/ip_segment.php'; $res = self::_write($file, $ip_segment); if ($res) { echo 'Update OK!'; } }根据省份名(中文)随机生成IPV4地址$province为空则随机国内省份
(function(w){ // the heatmapFactory creates heatmap instances var heatmapFactory = (function(){ // store object constructor // a heatmap contains a store // the store has to know about the heatmap in order to trigger heatmap updates when datapoints get added var store = function store(hmap){ var _ = { // data is a two dimensional array // a datapoint gets saved as data[point-x-value][point-y-value] // the value at [point-x-value][point-y-value] is the occurrence of the datapoint data: [], // tight coupling of the heatmap object heatmap: hmap }; // the max occurrence - the heatmaps radial gradient alpha transition is based on it this.max = 1; this.get = function(key){ return _[key]; }; this.set = function(key, value){ _[key] = value; }; }设置热力图展现的详细数据, 实现之后,即可以立刻展现 @param {Json Object } data{"<b>max</b>" : {Number} 权重的最大值,<br />"<b>data</b>" : {Array} 坐标详细数据,格式如下 <br/>{"lng":116.421969,"lat":39.913527,"count":3}, 其中<br/>lng lat分别为经纬度, count权重值添加势力图的详细坐标点@param {Number} lng 经度坐标@param {Number} lat 经度坐标@param {Number} count 经度坐标
<?php /** * 阿里云短信验证码发送类 */ class Sms { // 保存错误信息 public $error; // Access Key ID private $accessKeyId = ''; // Access Access Key Secret private $accessKeySecret = ''; // 签名 private $signName = ''; // 模版ID private $templateCode = ''; public function __construct($cofig = array()) { $cofig = array ( 'accessKeyId' => '***************', 'accessKeySecret' => '******************', 'signName' => '七零', 'templateCode' => 'SMS_25300059' ); // 配置参数 $this->accessKeyId = $cofig ['accessKeyId']; $this->accessKeySecret = $cofig ['accessKeySecret']; $this->signName = $cofig ['signName']; $this->templateCode = $cofig ['templateCode']; }InvalidDayuStatus.Malformed' => '账户短信开通状态不正确',InvalidSignName.Malformed' => '短信签名不正确或签名状态不正确',InvalidTemplateCode.MalFormed' => '短信模板Code不正确或者模板状态不正确',InvalidRecNum.Malformed' => '目标手机号不正确,单次发送数量不能超过100',InvalidParamString.MalFormed' => '短信模板中变量不是json格式',InvalidParamStringTemplate.Malformed' => '短信模板中变量与模板内容不匹配'InvalidSendSms' => '触发业务流控InvalidDayu.Malformed' => '变量不能是url,可以将变量固化在模板中
<?php class HttpDownload { private $m_url = ""; private $m_urlpath = ""; private $m_scheme = "http"; private $m_host = ""; private $m_port = "80"; private $m_user = ""; private $m_pass = ""; private $m_path = "/"; private $m_query = ""; private $m_fp = ""; private $m_error = ""; private $m_httphead = "" ; private $m_html = ""; public function PrivateInit($url){ $urls = ""; $urls = @parse_url($url); $this->m_url = $url; if(is_array($urls)) { $this->m_host = $urls["host"]; if(!empty($urls["scheme"])) $this->m_scheme = $urls["scheme"]; if(!empty($urls["user"])) $this->m_user = $urls["user"]; if(!empty($urls["pass"])) $this->m_pass = $urls["pass"]; if(!empty($urls["port"])) $this->m_port = $urls["port"]; if(!empty($urls["path"])) $this->m_path = $urls["path"]; $this->m_urlpath = $this->m_path; if(!empty($urls["query"])) { $this->m_query = $urls["query"]; $this->m_urlpath .= "?".$this->m_query; } } }初始化-打开指定网址--重设各参数-初始化系统-获得某操作错误的原因-判别用Get方法发送的头的应答结果是否正确-看看返回的网页是否是text类型-判断返回的网页是否是特定的类型- HTTP 协议下载文件
<?php function qsort(&$arr) { _quick_sort($arr, 0, count($arr) - 1); } function _quick_sort(&$arr, $low, $high) { $low_data = $arr[$low]; $prev_low = $low; $prev_high = $high; while ($low < $high) { while ($arr[$high] >= $low_data && $low < $high) { $high--; } if ($low < $high) { $arr[$low] = $arr[$high]; $low++; } while ($arr[$low] <= $low_data && $low < $high) { $low++; } if ($low < $high) { $arr[$high] = $arr[$low]; $high--; } }采用递归算法的快速排序。@param array $arr 要排序的数组@param int $low 最低的排序子段@param int $high 最高的排序字段