Aspire framework的.htaccess内容

自己所编写的一个框架,要用的apache的rewrite规则,.htaccess内容很不易记特写出来 ,以作备忘。

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

发表评论 2009年06月16日 星期二 12:03 streen003

在win下的apache与php的配置

用久vertrigo了,在win下配置PHP环境日渐远去,今天同事问我如何配置,在PHPCHINA接受培训时发现一种新的方法,比我原来的方法要简单,只所以简单就是把PHP.INI文件直接放在PHP执行文件目录里,(以前放在c:/windows/或c:/windows/system32目录下,如需修改PHP的配置时,扒开c:/windows/或c:/windows/system32目录找PHP.INI在众多的文件中找到PHP.INI的藏身之处费好长时间,现在直接放在PHP的执行目录里打开一目了然,实在是很方便)
下面就具体细节详细说一下:
一,PHP.INI的设置
在PHP执行目录里(我这里是PHP)
把php.ini-recommended或php.ini-dist改成PHP.INI
设置:

doc_root ="XXOO"

extension_dir = "XXOO"

如有必要
开启
session.save_path
设置一个存在且有可写权限的目录
开启PHP扩展如MYSQL,MYSQLI,GD2等
二,HTTPD.CONF的设置
apache的conf目录里
打开httpd.conf文件
设置

DocumentRoot "XXoo"

<directory "XXoo">

<ifmodule dir_module>
    DirectoryIndex index.php index.html
</ifmodule>

在最下面加入:

PHPIniDir "PHP.INI的目录"
LoadModule php5_module "php执行文件目录/php5apache2_2.dll"

在同目录下
打开mime.types
加入

application/x-httpd-php  php

最后将PHP执行目录下的
libmysql.dll,libmcrypt.dll等LIB文件CTRL+X到
apache目录中bin中
重启apache
运行phpinfo();查看结果
好,一切搞定。这种配置方法比传统的配置方法来说,操作也很简单。关键是以后修改PHP配置非常方便。

发表评论 2009年06月15日 星期一 21:01 streen003

能吹是多么的重要…

联合利华引进了一条香皂包装生产线,结果发现这条生产线有个缺陷:常常会有盒子里没装入香皂。总不能把空盒子卖给顾客啊,他们只得请了一个学自动化的博士后设计一个方案来分拣空的香皂盒。博士后拉起了一个十几人的科研攻关小组,综合采用了机械、微电子、自动化、X射线探测等技术,花了几十万,成功解决了问题。每当生产线上有空香皂盒通过,两旁的探测器会检测到,并且驱动一只机械手把空皂盒推走。 
中国南方有个乡镇企业也买了同样的生产线,老板发现这个问题后大为发火,找了个小工来说:你他妈给老子把这个搞定,不然你给老子爬走。小工很快想出了办法:他花了90块钱在生产线旁边放了台风扇猛吹,于是空皂盒都被吹走了。
这个故事告诉我们,能吹是多么的重要。。

发表评论 2009年06月13日 星期六 10:40 streen003

Aspire Model 用类控制数据库操作

学习了ZF的框架,对数据库操作这块感觉操作非常方便,利用对象代替了那繁杂的SQL语句,可得用ZF也够麻烦的,虽说它是弱藕合型的,对数据库操作的代码可以单独用,可初始化进还要在PHP.INI里设置incldueZF的路径,要么是在PHP页面开头set_incldue_path(xxoo);的操作,丫的,真麻烦。一怒之下本人自己也来写个。
经过几晚的调试,终于大功告成。
具体方法:
我把详细的操作过程写在了PHPCHINA上
PHPCHINA Aspire Model
程序下载地址:
NET BOX下载

发表评论 2009年06月12日 星期五 17:01 streen003

分享自己的Mysqli Class 完全的OOP风格(端午版)

端午节放假,编写一个Mysqli Class,完全采用了PHP5.0的OOP风格。现在贴出来,供初级PHPER研究。

// +---------------------------------------------------------------
// |    Mysqli_db Class
// +---------------------------------------------------------------
// | Copyright (c) 2009 http://www.bc263.com All rights reserved.
// +---------------------------------------------------------------
// | Author: streen003 &lt;streen0032gmail.com&gt;
// +---------------------------------------------------------------

class Mysqli_db {

//定义变量
public $db_link;
public $result;
public $rows;
public $myrow;

protected $sql_version;

//构造函数,用于初始化类的应用环境
public function __construct($params) {

$this-&gt;db_link = new mysqli($params['host'],$params['username'],$params['password'],$params['dbname']);

if (mysqli_connect_errno()) {
trigger_error('Mysql Server connect fail &lt;br&gt;Error Message: '.mysqli_connect_error().'&lt;br&gt;Error Code: '.mysqli_connect_errno(),E_USER_ERROR);
}
else {

$this-&gt;db_link-&gt;query("SET NAMES {$params['charset']}");
$this-&gt;get_server_info();
if (version_compare($this-&gt;sql_version,'5.0.2','&gt;=')) {
$this-&gt;db_link-&gt;query("SET SESSION SQL_MODE=''");
}
}

return true;
}

//执行SQL语句函数
public function query($sql) {

if ($this-&gt;result) {
unset($this-&gt;result);
}

$this-&gt;result = $this-&gt;db_link-&gt;query($sql);

return $this-&gt;result;

}

//获取MYSQL SERVER信息
public function get_server_info() {

if ($this-&gt;db_link) {
$this-&gt;sql_version = $this-&gt;db_link-&gt;server_version;
return $this-&gt;sql_version;
}
else {
return false;
}
}

//获取MYSQL 错误描述信息
public function error() {
return $this-&gt;db_link-&gt;error;
}

//获取MYSQL 错误信息代码
public function errno() {
return $this-&gt;db_link-&gt;errno;
}

//通过一个SQL语句获取一行信息(字段型)
public function fetch_row($sql) {

if ($this-&gt;rows) {
unset($this-&gt;rows);
}

$this-&gt;query($sql);

if($this-&gt;result) {

$this-&gt;rows = $this-&gt;result-&gt;fetch_assoc();
}


return $this-&gt;rows;
}

//通过一个SQL语句获取一行信息(字段,数字型)
public function fetch_array($sql) {

if ($this-&gt;rows) {
unset($this-&gt;rows);
}

$this-&gt;query($sql);

if($this-&gt;result) {

$this-&gt;rows = $this-&gt;result-&gt;fetch_array();
}

return $this-&gt;rows;
}

//通过一个SQL语句获取全部信息(字段型)
public function get_array($sql) {

if ($this-&gt;myrow) {
unset($this-&gt;myrow);
}

$this-&gt;query($sql);

$myrow=array();

if($this-&gt;result) {

while ($row=$this-&gt;result-&gt;fetch_assoc()) {
$myrow[]=$row;
}
}

$this-&gt;free($this-&gt;result);

$this-&gt;myrow = $myrow;
return $this-&gt;myrow;
}

//通过一个SQL语句获取全部信息(字段,数字型)
public function get_all($sql) {

if ($this-&gt;myrow) {
unset($this-&gt;myrow);
}

$this-&gt;query($sql);

$myrow=array();

if($this-&gt;result) {

while ($row=$this-&gt;result-&gt;fetch_array()) {
$myrow[]=$row;
}
}

$this-&gt;fee($this-&gt;result);

$this-&gt;myrow=$myrow;
return $this-&gt;myrow;
}

//释放内存
public function free($result) {

return $result-&gt;free();
}

//获取执行结果的总行数
public function num_rows($result) {
return $result-&gt;num_rows;
}

//关闭MYSQL SERVER
public function close($db_link) {

if ($db_link) {
return $db_link-&gt;close();
}
else {
return false;
}
}

//处理当类外调用不存在的方法
public function __call($method,array $args) {

echo 'Class Mysqli_db method '.$method.' is not exists!&lt;br&gt;The args is:&lt;br&gt;';
foreach ($args as $val) {
echo $val.'&lt;br&gt;';
}
}
}

阅读全文…

发表评论 2009年05月30日 星期六 12:53 streen003

PHP中返回类的解决办法

在ZF中
$select->from('name','id')->where('id=?','5');
相当于
$select->from('name','id');
$select->where('id=?','5');

这个返回类是怎么实现的呢
看了/Zend/Db/Select.php的源码
再找到结果:
原来就一个:return $this;
演示一下:

class demo {

function a () {
$this->sql = 'This is A';
return $this;

}

function b () {
$this->sql .=  'This is B';
return $this;
}

function c () {
$this->sql .= 'This is C';
}

function __toString() {
return (string)$this->sql;
}

function __call($method,array $args) {
echo 'functiong '.$method .' is not exists <br />the args is:';
if(is_array($args)) {
foreach($args as $val) {
echo $val;
}
}
}

}

操作如下:

$demo = new demo();
$demo->a()->b()->c();
echo $demo;

显示:
This is A This is B This is C
实现这一返回类的一个关键:

return $this;

发表评论 2009年05月28日 星期四 14:31 streen003

DoitTemplate class 官方下载及使用说明

为了模拟Smarty的运行原理,自己也动手编写了一个编译型的Template class,用法与Smarty相同,只是功能没有Smarty强大,不过常用的功能都差不多有了。不过本template相比Smarty体积小了很多很多,执行速度相应要比Smarty快(已经进行了函数优化)。目前支持if, foreach,include语法结构。

现在共享出来 ,供初学PHP TEMPLALTE者研究。

/****************************
*
*   Name   : Doit Template
* Author : streen003   
*   Site   : www.bc263.com
*
* **************************/

class Template {

public $template_dir;  //模板文件存放目录
public $compile_dir;   //编译文件存放目录
public $cache_dir;     //缓存文件存放目录

public $caching;    //缓存弃置
public $cahce_lifetime;//缓存时间

private $filename;     
private $compilename;
private $cachename;

private $tpl_vars;
private $files;
private $putout;

private $compiel_on; //编译开关
private $cache_on; //缓存开关

public function __construct(){

$this->template_dir = 'template/';
$this->compile_dir = 'template_c/';
$this->cache_dir = 'cache/';

$this->filename = array();
$this->compilename = array();
$this->cachename = array();
$this->files = array();
$this->putout = array();

$this->compiel_on = false;
$this->cache_on = false;
$this->caching = false; //缓存默认为关闭
$this->cahce_lifetime = 60; //缓存时间周期默认为60秒
}

public function assign($handle,$value=false){

if(is_array($handle)) {

foreach ($handle as $k=>$v){

$this->tpl_vars[$k] = $v;
}
}
else{

$this->tpl_vars[$handle] = $value;
}

return true;
}

//设置模板文件,编译文件,缓存文件。
protected function set_template($filename){

if(file_exists($this->template_dir . $filename)){

$this->filename[$filename] = $this->template_dir . $filename;
$this->compilename[$filename] = $this->compile_dir . $filename . '.php';
$this->cachename[$filename] = $this->cache_dir . $filename;
}
else {
trigger_error('The file :' . $filename . 'could not exists', E_USER_ERROR);
}

return true;
}

//读取模板文件
protected  function get_file($filename){

if(isset($this->filename[$filename])){

$this->files[$filename] = file_get_contents($this->filename[$filename]);

return $this->files[$filename];
}
else{
return false;
}
}

//写入编译文件,缓存文件
protected function put_file($filename,$option=false) {

if($option == true){

if(isset($this->cachename[$filename]) && isset($this->putout[$filename])){

file_put_contents($this->cachename[$filename],$this->putout[$filename]);
}
else {

return false;
}
}
else {

if(isset($this->compilename[$filename]) && isset($this->files[$filename])){

file_put_contents($this->compilename[$filename],$this->files[$filename]);
}
else {

return false;
}
}
}

//将读取的模板文件进行处理
protected function handle_template($filename){

if(isset($this->files[$filename])){

$regex = array(
'#\{\s*\$(\w+?)\s*\}#i',
'#\{\s*include\s+file=(.*?)\s*\}#is',
'#\{\s*if\s+\$(\w+?)\s*==\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*\}#i',
'#\{\s*\/if\s*\}#i',
'#\{\s*foreach\s+item=\$(\w+?)\s+key=\$(\w+?)\s+value=\$(\w+?)\s*\}#is',
'#\{\s*\/foreach\s*\}#i',
'#\{\s*if\s+\$(\w+?)\s*(!==)\s*\$(\w+?)\s*}#i',
'#\{\s*if\s+\$(\w+?)\s*>=\s*\$(\w+?)\s*}#i',
'#\{\s*if\s+\$(\w+?)\s*>\s*\$(\w+?)\s*}#i',
'#\{\s*if\s+\$(\w+?)\s*< =\s*\$(\w+?)\s*}#i',
'#\{\s*if\s+\$(\w+?)\s*<\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*if\s+\$(\w+?)\s*==\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*if\s+\$(\w+?)\s*(!==)\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*if\s+\$(\w+?)\s*>=\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*if\s+\$(\w+?)\s*>\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*if\s+\$(\w+?)\s*< =\s*\$(\w+?)\s*}#i',
'#\{\s*else\s*if\s+\$(\w+?)\s*<\s*\$(\w+?)\s*}#i',
'#\{\s*foreach\s+item=\$(\w+?)\s+value=\$(\w+?)\s*\}#i',
);

$replace = array(
'<?php echo $this->tpl_vars[\'\\1\'] ?>',
'< ?php $this->handle_include(\\1) ?>',
'< ?php if( $this->tpl_vars[\'\\1\'] == $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php } else { ?>',
'< ?php } ?>',
'< ?php foreach($this->tpl_vars[\'\\1\'] as $this->tpl_vars[\'\\2\']=>$this->tpl_vars[\'\\3\']) { ?>',
'< ?php } ?>',
'< ?php if( $this->tpl_vars[\'\\1\'] !== $this->tpl_vars[\'\\3\'] ) { ?>',
'< ?php if( $this->tpl_vars[\'\\1\'] >= $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php if( $this->tpl_vars[\'\\1\'] > $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php if( $this->tpl_vars[\'\\1\'] < = $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php if( $this->tpl_vars[\'\\1\'] < $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php } else if( $this->tpl_vars[\'\\1\'] == $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php } else if( $this->tpl_vars[\'\\1\'] !== $this->tpl_vars[\'\\3\'] ) { ?>',
'< ?php } else if( $this->tpl_vars[\'\\1\'] >= $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php } else if( $this->tpl_vars[\'\\1\'] > $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php } else if( $this->tpl_vars[\'\\1\'] < = $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php } else if( $this->tpl_vars[\'\\1\'] < $this->tpl_vars[\'\\2\'] ) { ?>',
'< ?php foreach($this->tpl_vars[\'\\1\'] as $this->tpl_vars[\'\\2\']) { ?>',
);

$this->files[$filename] = preg_replace($regex, $replace, $this->files[$filename]);

return  $this->files[$filename];

}
else{

return false;
}
}

//将处理完毕的内容写入编译文件
protected function compile_template($filename){

$this->get_file($filename);

$this->handle_template($filename);

$this->put_file($filename);
}

//是否对编译文件进行重新写入开关
protected function check_compile($filename){

if(isset($this->filename[$filename])&& isset($this->compilename[$filename])){

if (file_exists($this->compilename[$filename])){

if (filemtime($this->filename[$filename]) > filemtime($this->compilename[$filename])){

$this->compiel_on = true;
}
else {

$this->compiel_on = false;
}
}
else {

$this->compiel_on = true;
}

return $this->compiel_on;
}
else {

return false;
}
}

//是否对缓存文件进行重新写入开关
protected function check_cache($filename){

if(isset($this->cachename[$filename])){

if (file_exists($this->cachename[$filename])){

$time_now = $_SERVER['REQUEST_TIME'];

if ($time_now - filemtime($this->cachename[$filename]) > $this->cahce_lifetime){

$this->cache_on = true;
}
else {

$this->cache_on = false;
}

return $this->cache_on;
}
else {

return $this->cache_on = true;
}
}
else {
return false;
}
}

//加载编译文件
protected function load_compile($filename){

$this->check_compile($filename);

if($this->compiel_on ==true){

$this->compile_template($filename);
}

if (isset($this->putout[$filename])){

unset($this->putout[$filename]);
}

ob_start();

include ($this->compilename[$filename]);

$this->putout[$filename] = ob_get_clean();

return $this->putout[$filename];
}

//inclue文件的处理
protected function handle_include($filename){

$this->set_template($filename);
$this->check_compile($filename);

if ($this->compiel_on == true){

$this->compile_template($filename);
}

include ($this->compilename[$filename]);

return true;
}

//显示页面内容
public function display($filename){

$this->set_template($filename);

if ($this->caching == true){

$this->check_cache($filename);

if ($this->cache_on == true){

$this->load_compile($filename);

$this->put_file($filename,true);

echo $this->putout[$filename];
}
else {

include ($this->cachename[$filename]);
}
}
else {

$this->load_compile($filename);
echo $this->putout[$filename];
}
}

//析构函数,清空所有的临时变量
public function __destruct(){

$this->filename = array();
$this->compilename = array();
$this->cachename = array();
$this->files = array();
$this->putout = array();
}

}

使用说明:
阅读全文…

1 条评论 2009年05月17日 星期日 14:23 streen003

php正则表达式提取邮箱地址

匹配邮箱地址:

#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+\.)?[\w\-]+#is

匹配网址:

#(http|https|ftp|ftps):\/\/\w.+#i

发表评论 2009年05月07日 星期四 17:48 streen003

db_mysql_class程式

今天还是进行搭基木式的开发,先写个MYSQL数据库操作的类(想把程序写的强壮一点,可是对OOP风格的代码以前写的太少,从现在开始严格要求自己:以后的每个程序都尽可能的用OOP,哪怕是写个hello world也要用OOP,寡人就不信邪,寡人就不相信掌握不了它)。


/*
* NAME : MYSQL_CLASS
* AUTHOR : streen003
* FROM: www.bc263.com
* EMAIL:streen003@gmail.com
*
*/

class Db_mysql {

//定义变量
private $db_link;

private $host_name;

private $user_name;

private $password;

private $charset;

private $result;

private  $row;

private  $db_name;

function __construct($hostname,$username,$password,$dbname,$charset) {

$this->host_name = $hostname;
$this->user_name = $username;
$this->password = $password;
$this->db_name = $dbname;
$this->charset = $charset;

if($this->host_name !=='' && $this->user_name !=='' && $this->password !=='' && $this->db_name !== '' && $this->charset !== '') {

$this->connect();

}
}

//连接数据库
private   function connect() {

$this->db_link = mysql_connect($this->host_name,$this->user_name,$this->password);
if($this->db_link){

mysql_select_db($this->db_name,$this->db_link);
$mysql_version = mysql_get_server_info($this->db_link);

if(version_compare($mysql_version,'4.1.3','>=')) {

mysql_query("SET NAMES {$this->charset}",$this->db_link);

if(version_compare($mysql_version,'5.0.2','>=')) {
mysql_query("SET sql_mode = ''",$this->db_link);
}

}
}
else {
trigger_error('could not connect mysql server',E_USER_ERROR);
}

return true;
}

public  function query($sql) {

if($sql !== ''){

if($this->result) {

unset($this->result);
}

$this->result = mysql_query($sql,$this->db_link);

if($this->result){

return $this->result;
}
else {
trigger_error('sql query is wrong,please check it',E_USER_ERROR);
}
}
else {
return  false;
}
}

public  function fetch_row ($result) {

if($result !== ''){

$this->row = mysql_fetch_assoc($result);

return  $this->row;

}
else {

return false;
}

}

public  function fetch_array($result){

if($result !== '') {
$this->row = mysql_fetch_array($result,MYSQL_ASSOC);
return  $this->row;
}
else {
return  false;
}
}

public  function  free_result($result) {

if($result !=='') {

return mysql_freeresult($result);
}
else {
return false;
}
}

public function db_close() {

if($this->db_link) {

return mysql_close($this->db_link);
}
else {
return false;
}
}
}

发表评论 2009年05月07日 星期四 17:12 streen003

Javascript日历

前天用PHP编写了一个日历程序,今天也试着用JS编写一个日历,用Javascript编写,感觉没有PHP所提供的函数强大,特别是计算当月的总天数还得另行设置个数组,很机械地判断当月的总天数,还有闰年也得判断,一句话麻烦。现在把函数贴出来,抛砖引玉吧。

function calendar()
{
    function doc(id)
{
return document.write(id);
}

var total_days = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var day_name = new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');

var this_time = new Date();

year = this_time.getFullYear();
 
month = this_time.getMonth()+1;

date = this_time.getDate();

day = this_time.getDay();

this_time.setDate(1);

day_first = this_time.getDay();
    
if( ((year%4 == 0)&&(year%100 !==0)) || (year%400 == 0) )
{
         total_days[1] = 29;
}
 
total_lines = Math.ceil((total_days[month-1]+day_first)/7);

doc('<table width="210" style="border:1px solid #FF0000 ">');
doc('<tr><td colspan="7" align="center">' + year +' 年' + month +  ' 月 ' + day_name[day] + '</td></tr>');
doc('<tr align="center" bgcolor="#FF6600"><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>');

for(i=0; i< total_lines; i++)
{
doc('<tr>');

for(k=0; k< 7; k++)
{

num = parseInt( 7*i + k - day_first +1);

if( num < 1 || num > total_days[month-1] )
{
doc('<td>&nbsp;</td>');
}
else
{   
if(num == date)
{
doc ('<td bgcolor=red>'+ num +'</td>');
}
else
{
doc ('<td>'+ num +'</td>');
}
}

}

doc('');

}

doc('</table>');

}

发表评论 2009年04月30日 星期四 17:57 streen003


文章分类

订阅博客

常用网址

学习资料

标签集锦

Feeds