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

快速开发一个PHP扩展

 快速开发一个PHP扩展
 
本文通过非常快速的方式讲解了如何制作一个PHP 5.2 环境的扩展(PHP Extension),希望能够在图文的方式下让想快速学习的朋友了解一下制作过程。
需求:比如开发一个叫做 heiyeluren  的扩展,扩展里就一个函数 heiyeluren_test(),输入一个字符串,函数返回:Your input string: xxxxx。
要求:了解C/C++编程,熟悉PHP编程
环境:下载一份php对应版本的源码,我这里是 php-5.2.6,先正常安装php,假设我们的php安装在 /usr/local/php 目录,源码在 /root/soft/php/php-5.2.6/,现在开始!
步骤一:生成扩展框架
cd /root/soft/php/php-5.2.6/ext
./ext_skel --extname=heiyeluren
cd /root/soft/php/php-5.2.6/ext/heiyeluren
vi config.m4
打开文件后去掉 dnl ,获得下面的信息:
PHP_ARG_ENABLE(heiyeluren, whether to enable heiyeluren support,
[  --enable-heiyeluren           Enable heiyeluren support])
保存退出.
(图01)
 
第二步:编写代码
vi php_heiyeluren.h
找到:PHP_FUNCTION(confirm_heiyeluren_compiled); ,新增一行:
PHP_FUNCTION(heiyeluren_test);
保存退出。
(图02)
vi heiyeluren.c
数组里增加我们的函数,找到 zend_function_entry heiyeluren_functions[],增加:
PHP_FE(heiyeluren, NULL)
(图03)
再到 heiyeluren.c 文件最后面增加如下代码:
PHP_FUNCTION(heiyeluren_test)
{
    char *arg = NULL;
    int arg_len, len;
    char *strg;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
        return;
    }
    len = spprintf(&strg, 0, "Your input string: %s\n", arg);
    RETURN_STRINGL(strg, len, 0);
}
保存退出。
(图04)
第三步:编译安装
cd /root/soft/php/php-5.2.6/ext/heiyeluren
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make test
make install
现在看看是不是有个 /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/heiyeluren.so
编辑php.ini,把


相关文档:

在vim中使用xdebug调试PHP程序

 操作系统centos 5.3,php 5.1.6, xdebug 2.0.5。
主要参考文档:
xdebug的安装文档:http://xdebug.org/docs/install。
xdebug的远程调试配置文档:http://xdebug.org/docs/remote
Using vim and xdebug DBGp for debugging Drupal (or any PHP application):
http://2bits.com/articles/using-vim-and-xdebug- ......

php中echo(),print(),print_r()的区别

1.echo()是一个php语句,所以没有返回值,能打印简单的数据。
2.print()是一个函数,有返回值,能打印简单的数据。
3.print_r()是一个函数,能打印复杂的(mix)数据。
如:
<?
$value = print 'hello word<br>';
echo "the value is $value<br>";
$arr = array('name'=>'wangking','qq'=>'12345 ......

PHP字符串教程_trim函数

PHP trim() 函数
定义和用法
trim() 函数从字符串的两端删除空白字符和其他预定义字符。
语法
trim(str,charlist)
 参数 1 str为待操作的字符串,参数 2 charlist 可选,指定了想要去除的特殊符号。
如果第二个参数没给值,预设会去除下列这些字元: 
" " (ASCII 32 (0x20) ......

php中的ewebeditor表单调用

 相关参数:<textarea name=content>
模板调用符:$
  提交新表单的时候用如下代码,结果完全正常:
<form name="frm_HelpMessageAdd" id="frm_HelpMessageAdd" action="manage.php" method="POST" enctype="multipart/form-data">
<input name="content" type="hidden" id="shopProduct_Intro"& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号