Zend Studio For Eclipse 6.0 实用快捷键

2009年2月25日

ZendChina官方:为了方便开发者的使用,提高开发效率,下面对Zend Studio For Eclipse 6.0的快捷键的功能进行详细介绍。

Ctrl+1 快速修复(最经典的快捷键,就不用多说了)
Ctrl+D: 删除当前行
Ctrl+Alt+↓ 复制当前行到下一行(复制增加)
Ctrl+Alt+↑ 复制当前行到上一行(复制增加)
Alt+↓ 当前行和下面一行交互位置(特别实用,可以省去先剪切,再粘贴了)
Alt+↑ 当前行和上面一行交互位置(同上)
Alt+← 前一个编辑的页面
Alt+→ 下一个编辑的页面(当然是针对上面那条来说了)
Alt+Enter 显示当前选择资源(工程,or 文件 or文件)的属性
Shift+Enter 在当前行的下一行插入空行(这时鼠标可以在当前行的任一位置,不一定是最后)
Shift+Ctrl+Enter 在当前行插入空行(原理同上条)
Ctrl+Q 定位到最后编辑的地方
Ctrl+L 定位在某行 (对于程序超过100的人就有福音了)
Ctrl+M 最大化当前的Edit或View (再按则反之)
Ctrl+/ 注释当前行,再按则取消注释
Ctrl+O 快速显示 OutLine
Ctrl+T 快速显示当前类的继承结构
Ctrl+W 关闭当前Editer
Ctrl+K 参照选中的Word快速定位到下一个
Ctrl+E 快速显示当前Editer的下拉列表(如果当前页面没有显示的用黑体表示)
Ctrl+/(小键盘) 折叠当前类中的所有代码
Ctrl+×(小键盘) 展开当前类中的所有代码
Ctrl+Space 代码助手完成一些代码的插入(但一般和输入法有冲突,可以修改输入法的热键,也可以暂用Alt+/来代替)
Ctrl+Shift+E 显示管理当前打开的所有的View的管理器(可以选择关闭,激活等操作)
Ctrl+J 正向增量查找(按下Ctrl+J后,你所输入的每个字母编辑器都提供快速匹配定位到某个单词,如果没有,则在stutes line中显示没有找到了,查一个单词时,特别实用,这个功能Idea两年前就有了)
Ctrl+Shift+J 反向增量查找(和上条相同,只不过是从后往前查)
Ctrl+Shift+F4 关闭所有打开的Editer
Ctrl+Shift+X 把当前选中的文本全部变为小写
Ctrl+Shift+Y 把当前选中的文本全部变为小写
Ctrl+Shift+F 格式化当前代码
Ctrl+Shift+P 定位到对于的匹配符(譬如{}) (从前面定位后面时,光标要在匹配符里面,后面到前面,则反之)

ZendChina官方资讯,转载请以链接形式注名来源:ZendChina - Zend Studio For Eclipse 6.0 实用快捷键

admin PHP

Craigie Hill - Cara Dillon

2009年2月25日

戒烟第二日. 送首Cara Dillon的Craigie Hill, Listen carefully and then…you get touched.
Craigie Hill - Cara Dillon
cara_dillon

it being in the springtime
and the small birds they were singing,
down by yon shady harbour
i carelessly did stray,
the thrushes they were warbling,
the violets they were charming
to view fond lovers talking,
a while i did delay.

she said, my dear don’t leave me
all for another season,
though fortune does be pleasing
i ‘ll go along with you,
i ‘ll forsake friends and relations
and bid this irish nation,
and to the bonny bann banks
forever i ‘ll bid adieu.

he said, my dear don’t grieve
or yet annoy my patience,
you know i love you dearly
the more i’m going away,
i’m going to a foreign nation
to purchase a plantation,
to comfort us hereafter
all in amerikay.

then after a short while
a fortune does be pleasing,
i’will cause them for smile
at our late going away,
we’ll be happy as queen victoria,
all in her greatest glory,
we’ll be drinking wine and porter
all in amerikay.

if you were in your bed lying
and thinking on dying,
the sight of the lovely bann banks,
your sorrow you’d give over,
or if were down one hour,
down in you shady bower,
pleasure would surround you,
you’d think on death no more.

then fare you well,sweet cragie hills,
where often times i’ve roved,
i never thought my childhood days
i ‘d part you any more,
now we’re sailing on the ocean
for honour and promotion,
and the bonny boats are sailing,
way down by doorin shore

admin 音乐

PDO下的数据缓存

2009年2月24日

原文地址:http://bbs.phpchina.com/viewthread.php?tid=58800&extra=&highlight=pdo&page=1

这是基于文件系统的一个数据缓存, 思路方法还不错, 转载了一下. 缓存和数据耦合这块代码实现还值得商榷

注:源代码我略加修改,以下是改过后的代码

<?php
class MyCacheDB extends PDO {
	private $_cache = array("cacheDir" => "cache", "cacheExpire" => 7200);
 
	// 缓存读取
	public function cquery($sql) {
		if ($this->_cache['cacheDir'] == null
			|| !is_dir($this->_cache['cacheDir']))
			exit('缓存目录不存在');
		else {
			$this->_cache['cacheDir'] = str_replace("\\", "/", $this->_cache['cacheDir']);
			$fileName = trim($this->_cache['cacheDir'], "/").'/'.urlencode(trim($sql)).'.sql';
		}
 
		// 判断缓存
		if (!file_exists($fileName) 
			|| time() - filemtime($fileName) > $this->_cache['cacheExpire']) {
			if ($tmpRS = parent::query($sql)) {
				$data = serialize($tmpRS->fetchAll());
				$this->createFile($fileName, $data);
			}
			else {
				exit('SQL错误');
			}
		}
		return $this->readCache($fileName);
	}
 
	// 读取缓存文件
	private function readCache($fileName) {
		if (is_file($fileName) && $data = file_get_contents($fileName)) {
			return new CachedStatement(unserialize($data));
		}
		return false;
	}
 
	// 生成文件
	private function createFile($fileName, $data = '') {
		if (file_put_contents($fileName, $data))
			return true;
		return false;
	}
 
	public function __set($k, $v) {
		if (array_key_exists($k, $this->_cache))
			$this->_cache[$k] = $v;
		else
			throw new Exception('属性不存在');
	}
 
	public function __get($k) {
		return isset($this->_cache[$k]) ? $this->_cache[$k] : null;
	}
}
 
 
// 缓存
class CachedStatement {
	private $_record = array();
	private $_cursorId = 0;
	private $_recordCnt = 0;
 
	public function __construct($record) {
		$this->_record = $record;
		$this->_recordCnt = count($record);
	}
 
	public function fetch() {
		if ($this->cursorId == $this->_recordCnt)
			return false;
		else if ($this->_cursorId == 0) {
			$this->_cursorId++;
			return current($this->_record);
		}
		else {
			$this->_cursorId++;
			return next($this->_record);
		}
	}
 
	public function fetchAll() {
		return $this->_record;
	}
 
	public function fetchColumn() {
		$tmp = current($this->_record);
		return $tmp[0];
	}
}
 
 
header('content-type:text/html; charset=utf-8');
 
$db = new MyCacheDB('mysql:host=localhost;dbname=test','root','xxx', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'")); 
 
$db->cacheDir = "cache"; //设置缓存目录
$db->cacheExpire = 7200; //设置缓存时间
 
$rs = $db->cquery("select * from news limit 0,10"); //用缓存查询方法cquery代替query
while ($row = $rs->fetch()) {
 echo $row["title"] . "<br />";
}
 
$rs = null;
$db = null;
 
?>

admin PHP ,

戒烟第一日.

2009年2月24日

终于还是做决定了, 在上次戒了三个月失败之后, 再次戒烟! 总结教训上次戒烟失败的主要原因还是毅力不够.
1) 知道自己喝酒时喜欢抽烟, 那就尽量避免喝酒,或者就不喝酒.尽量不去饭局,早点回家陪老婆,或者学习,打游戏.
2) 别人给烟,自己回绝的态度要坚决,不要怕不好意思,就说已经戒烟了.
3) 尽量避免,少去抽烟的地方.

为了孩子,老婆,父母,自己一定要下定决心,彻底戒掉. 想想可恶的咽炎,鼻炎,每天起来干吐的感觉….戒!!

如何戒烟(一):

1.戒烟从现在开始,完全戒烟或逐渐减少吸烟次数的方法,通常3~4个月就可以成功。
2.丢掉所有的香烟、打火机、火柴和烟灰缸。
3.避免参与往常习惯吸烟的场所或活动。
4.餐后喝水、吃水果或散步,摆脱饭后一支烟的想法。
5.烟瘾来时,要立即做深呼吸活动,或咀嚼无糖分的口香糖,避免用零食代替香烟,否则会引起血糖升高,身体过胖。
6.坚决拒绝香烟的引诱,经常提醒自己,再吸一支烟足以令戒烟的计划前功尽弃。

如何度过戒烟最难熬的前5天?提供以下七项戒烟方法(二):

(l)两餐之间喝6-8杯水,促使尼古丁排出体外。
(2)每天洗温水浴,忍不住烟瘾时可立即淋裕
(3)在戒烟的5日当中要充分休息,生活要有规律。
(4)饭后到户外散步,做深呼吸15—30分钟。
(5)不可喝刺激性饮料,改喝牛奶、新鲜果汁和谷类饮料。
(6)要尽量避免吃家禽类食物、油炸食物、糖果和甜点。
(7)可吃多种维生素B群,能安定神经除掉尼古丁

医师指出,过了最初五天可按照下列方法保持戒烟“战果”

(1)饭后刷牙或漱口,穿干净没烟味的衣服。
(2)用钢笔或铅笔取代手持香烟的习惯动作。
(3)将大部分时间花在图书馆或其它不准抽烟的地方。
(4)避免到酒吧和参加宴会,避免与烟瘾很重的人在一起。
(5)将不抽烟省下的钱给自己买一项礼物。
(6)准备在2—3周戒除想抽烟的习惯。

戒烟没问题,重要是恒心。努力冲吧。

我要用视死如归的精神来戒烟!加油吧flywolf!!!

admin 生活

PHP中的__call(),__set()和__get()

2009年2月23日

利用__call()在php中实现重载

<?php
class Test {
	public function __call($fun, $args) {
		if (method_exists($this, $fun.count($args))) {
			return call_user_func_array(array(&$this, $fun.count($args)), $args);
		}
		else {
			throw new Exception('调用了未知方法:'.get_class($this).'->'.$fun);
		}
	}
 
    //一个参数的方法
	public function foo1($a) {
			echo "你在调用一个参数的方法,参数为:".$a;
	}
    //两个参数的方法
	public function foo2($a, $b) {
			echo "你在调用两个参数的方法,参数为:".$a."和".$b;
	}
}
 
$test = new Test();
$test->foo("a");
$test->foo("a", "b");
$test->foo("a", "b", "c");
?>

执行结果如下:
你在调用一个参数的方法,参数为:a
你在调用两个参数的方法,参数为:a和b

Fatal error: Uncaught exception ‘Exception’ with message ‘调用了未知方法:Test->foo’…

再来看看神奇的__set()和__get()

<?php
class Test {
	private $_vars = array();
 
	public function __set($k, $v) {
		$this->_vars[$k] = $this->validate($v);
	}
 
	public function __get($k) {
		return isset($this->_vars[$k]) ? $this->_vars[$k] : null;	
	}
 
	private function validate($v) {
		return htmlspecialchars(addslashes($v));
	}
}
 
$test = new Test();
$test->foo = "哈哈";
$test->bar = "嘿嘿";
echo $test->foo;
echo $test->bar;
?>

“)

admin PHP

几个常用的正则表达式

2009年2月21日

摘录自PHPer第16期

1 使用正则表达式来检测HTML 是否关闭

function check_html($html) {
preg_match_all("/&lt;([a-zA-Z0-9]+)\\s*[^\\/&gt;]*&gt;/",$html,$start_tags);
preg_match_all("/&lt;\\/([a-zA-Z0-9]+)&gt;/", $html, $end_tags);
if(count($start_tags[1]) != count($end_tags[1])) return false;
for($i = 0; $i &lt; count($start_tags[1]); $i++) {
if(!in_array($start_tags[1][$i], $end_tags[1])) return false;
}
return true;
}

2 匹配E-mail 格式

function check_email($email) {
if(preg_match("/^[\w\d!#$%&'*+-\/=?^`{|}~]+(\.[\w\d!#$%&'*+-\/=?^`{|}~]+)*@([a-z\d][-a-z\
d]*[a-z\d]\.)+[a-z][-a-z\d]*[a-z]$/", $eamil)) return true;
return false;
}

3 检测一个用户密码是否安全

function is_good_pw($pw) {
if(preg_match('/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{8,16}/', $pw)) {
return true;
}
return false;
}

4 匹配一个网站中的所有链接

function get_links($link) {
$html = file_get_contents($link);
$html = str_replace("\n", "", $html);
$html = preg_replace('/<a/i', "\n<a", $html);
$html = preg_replace('/<\/a>/', "</a>\n", $html);
preg_match_all('/<a\s*.*>.*?<\/a>/', $html, $matches);
return($matches);
}

admin PHP