首页 > 编程技术 > php

php扩展

发布时间:2016-11-25 16:10

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.111cn.net/mayongzhan - 马永占,myz,mayongzhan

php扩展分为两种.一种是php的扩展,一种是zend扩展.(传说中的,这是programing php里讲的).真的希望能有人发表一些关于zend扩展的东西.这才是真正的核心.
本来是要读下源码的.但是似乎php的源码很多.目前只能扫扫边边角角.如果有机会的话,会去读一下源码的.
其实扩展并不是很难,php已经给好了例子和扩展的工具.使用一下就可以了.
先下php源码,解压
然后到解压目录,ext下 执行./ext_stel --extname=myz
然后到解压目录,执行
./buildconf --force
./configure --with-myz=shared --其他的
make
make install

然后就能看到phpinfo()里面多了个myz了.

这里编译了好几次.好象每次都有新问题.多调试几次一定会成功的."妻儿"不舍

附:php源码包中两个重要的文件内容
README.EXT_SKEL
README.SELF-CONTAINED-EXTENSIONS

README.EXT_SKEL

(NOTE: you may also want to take a look at the pear package
      PECL_Gen, a PHP-only alternative for this script that
    supports way more extension writing tasks and is
    supposed to replace ext_skel completely in the long run ...)

WHAT IT IS

  It''s a tool for automatically creating the basic framework for a PHP module
  and writing C code handling arguments passed to your functions from a simple
  configuration file. See an example at the end of this file.

HOW TO USE IT

  Very simple. First, change to the ext/ directory of the PHP 4 sources. If
  you just need the basic framework and will be writing all the code in your
  functions yourself, you can now do

   ./ext_skel --extname=module_name

  and everything you need is placed in directory module_name.

  [ Note that GNU awk is likely required for this script to work.  Debian
    systems seem to default to using mawk, so you may need to change the
    #! line in skeleton/create_stubs and the cat $proto | awk line in
    ext_skel to use gawk explicitly. ]

  If you don''t need to test the existence of any external header files,
  libraries or functions in them, the module is already almost ready to be
  compiled in PH

< <?php
class Shtml
  {
    var $Templet;
    var $DataSource;
    var $Dir;
 
    var $fileName;
    var $mod;
    var $handle;
 
    function Shtml($fileName="")
    {
      $this->fileName=$fileName;
      $this->mod="wb";
      $this->handle=false;
 
      $this->Templet    = "";
      $this->DataSource  = array();
      $this->Dir      = "";
    }
   
    ///  <描述>
    ///  绑定数据源,参数为一数组。
    ///  </描述>
    function BindData($arr)
    {
      $this->DataSource = $arr;
    }
   
    ///  <描述>
    ///  设置文件存放路径。
    ///  </描述>
    function SetDir($dir)
    {
      $this->Dir = $dir;
    }
    function SetFileName($fileName)
    {
      return $this->fileName=$fileName;
    }
 
    function GetMod()
    {
      return $this->mod;
    }
    function SetMod($mod)
    {
      return $this->mod=$mod;
    }
    function Open()
    {
      if(substr($this->fileName,0,1)=="/")
        $this->fileName = $_SERVER[''DOCUMENT_ROOT''] . $this->fileName;
 

本文件可以用于自动创建目录下所有JPG图片的缩略图,放到图片目录下运行即可。
缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。



<?php
$config = array();
$config[''path''] = "./";
$config[''t_width''] = 120;
$config[''t_height''] = 98;
$config[''ignore''] = array("",".",

< 现在介绍与删除帖子相关的代码,首先重点看用于输出帖子列表的for循环,代码如下所示:

  循环体的前两句用于交错相邻行的背景色,以粗体显示的第 3句是关键,它输出了一个核选框控件,且控件的名称为“ids[]”,控件的值为相应的帖子的ID。控件名称中的方括号使得表单提交时,同名的核选框中的数据以数组的方式提交到服务器端。循环体的最后两句则根据帖子的删除标志显示不同图片。

  用于删除操作的按钮的HTML代码如下所示:

  按钮的链接都是调用JavaScript的do_submit()函数,只是传入的参数不同。do_submit()函数的定义代码如下所示:

 参数为search时,是对使用帖子搜索功能的处理;参数为其他值(即单击删除按钮传入的值)时,如果是all或none(即全部删除和全部恢复)则先调用selectAll()函数将表单中的核选框全部选中,然后再提交。selectAll()函数在op.js中的定义代码如下所示:

  该函数使用for循环遍历参数所指对象的所有子孙对象,如果子孙对象是核选框则将其checked属性设为true使其被选中。

<
标签:[!--infotagslink--]