易截截图软件、单文件、免安装、纯绿色、仅160KB

PHP类的自动加载

通常我们写一个类如下:
a.php
class A
{
public function __construct()
{
echo "hello world!";
}

page.php
require("a.php");
$a = new A(); 
我们是通过手工引用某个类的文件来实现函数或者类的加载
但是当系统比较庞大,以及这些类的文件很多的时候,这种方式就显得非常不方便了
于是PHP5提供了一个::auotload::的方法
我们可通过编写该方法来自动加载当前文件中使用的类文件
page.php
function __autoload($classname)
{
$class_file = strtolower($classname).".php";
if (file_exists($class_file)){
require_once($class_file);
}
}
$a = new A(); 
这样,当使用类A的时候,发现当前文件中没有定义A,则会执行autoload函数,并根据该函数实现的方式,去加载包含A类的文件
同时,我们可以不使用该方法,而是使用我们自定义的方法来加载文件,这里就需要使用到函数
bool spl_autoload_register ( [callback $autoload_function] ) 
page.php
function my_own_loader($classname)
{
$class_file = strtolower($classname).".php";
if (file_exists($class_file)){
require_once($class_file);
}
}
spl_autoload_register("my_own_loader");
$a = new A(); 
实现的是同样的功能
自定义的加载函数还可以是类的方法
class Loader
{
public static function my_own_loader($classname)
{
$class_file = strtolower($classname).".php";
if (file_exists($class_file)){
require_once($class_file);
}
}
}
// 通过数组的形式传递类和方法的名称
spl_autoload_register(array("my_own_loader","Loader"));
$a = new A(); 


相关文档:

php读取和创建word文档

总结下本人在日常工作中使用php操作word的一些实战。
方法一:利用php com模块
。也即利用word提供的本地api,所有只适用于windows系统上。
<?php
$word = new com('word.application') or die('无法打开word');
$word->Visiable = false;
$doc_file = '/path/to/doc';
$word->Open($doc_file);
$text = ' ......

ubuntu10.04配置apache+php+mysql

1.安装apache2.0
  sudo apt-get install apache2
  安装后在浏览器中打开:
 
 http://localhost/或者http://127.0.0.1
  如果出现It works!,那证明安装成功。
 
 2.安装PHP
  sudo apt-get install php
5 //安装PHP
5
 
 sudo apt-get install libapache2-mod-php5 //配置APACHE+PHP
  sud ......

Linux+Apache+Mysql+Php详细安装文档

所需软件源代码包:
httpd-2.2.4.tar.gz   mysql-5.0.27.tar.gz   php-5.2.1.tar.bz2
freetype-2.3.2.tar.gz   gd-2.0.34.tar.gz   jpegsrc.v6b.tar.gz
libpng-1.2.8.tar.bz2   libxml2-2.6.24.tar.bz2  zlib-1.2.2.tar.gz
安装顺序:apache -> mysql ......

PHP的smarty使用心得!

花了几个小时的时间研究一下,发现还是比较好用的!
smarty可以很好地将逻辑与表现分离,后台程序员和web前端工程师各干各的事,不像以前,php代码和html代码杂合在一起,后台程序员和前端前序员一起发飙,因为他们的技能要求更高了,都必须要懂对方的语言,呵呵!
网上介绍的配置太哆嗦了,也许是老版本的缘故的,因为我 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号