随笔分类 -  php那些事

php学习与积累
设计模式 适配器模式
摘要:适配器模式就是不修改原有类的基础上 加一个中间转换层,以使其符合新需求说白了,就是对原有类的扩展,怎么扩展,继承呗例如下: 1 _error = $error; 9 }10 11 public function getError() {12 return $this-... 阅读全文

posted @ 2014-12-03 15:07 zper 阅读(206) 评论(1) 推荐(0)

php插件phpthumb使用方法,一个demo
摘要:一、文件结构:二、新建 yoursite.com/phpthumb/.htaccess文件内容RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?thumb=$1 [L,QSA]三、yoursite.com/thumbs/index.php 文件内容$thumb_part){ if ($k != count($thumb_array)-2) { $image .= $thumb_part . '.'; 阅读全文

posted @ 2013-08-10 13:16 zper 阅读(1235) 评论(0) 推荐(0)

discuz数据库操作,记录备用
摘要:DB::table($tablename)获取正确带前缀的表名,转换数据库句柄,DB::delete($tablename, 条件,条数限制)删除表中的数据DB::insert($tablename, 数据(数组),是否返回插入ID,是否是替换式,是否silent)插入数据操作DB::update($tablename, 数据(数组)条件)更新操作DB::fetch(查询后的资源)从结果集中取关联数组,注意如果结果中的两个或以上的列具有相同字段名,最后一列将优先。DB::fetch_first($sql)取查询的第一条数据fetchDB::result_first($sql)查询结果集的第一个 阅读全文

posted @ 2013-07-24 23:25 zper 阅读(375) 评论(0) 推荐(0)

php接口、工厂函数
摘要://图像接口interface img{ public function getWidth(); public function getHeight(); public function getData();}//png图像处理class Img_PNG implements img{ private $width, $height, $data; public function __construct($file){ $this->file = $file; $this->parse(); } public functio... 阅读全文

posted @ 2013-07-07 11:20 zper 阅读(344) 评论(0) 推荐(0)

php单例模式,最简单的,便于理解
摘要:以下是一个最简单的单例类,留存以便参考class TestInstance{ static $instance; private $color; private function __construct(){ $this->color = 'red'; } private function __clone(){} static function getInstance(){ if(!(self::$instance instanceof self)) { self::$instance = n... 阅读全文

posted @ 2013-07-07 10:42 zper 阅读(245) 评论(0) 推荐(0)

php用foreach重组数组的两个方法
摘要:原来重组稍复杂些的数组都是直接改比如数组为:$arr = array( array( 'id'=>1, 'name'=>'a', ), array( 'id'=>2, 'name'=>'b', ), array( 'id'=>3, 'name'=>'c', ) );而我的目标数组:$arr = array( array( 'id' => 1, 'name'=>'ac 阅读全文

posted @ 2013-06-24 00:18 zper 阅读(1924) 评论(1) 推荐(0)

导航