日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

allowedExts php,通过php扩展增加一个内置函数

發布時間:2023/12/20 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 allowedExts php,通过php扩展增加一个内置函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在日常的調試中,我們經常需要輸出數組,但是print_r函數輸出的數組是沒有格式的,不太好看,

為了方便,我們只要自己增加一個函數,如

function dump($arr) {

echo '< pre>';

print_r($arr);

echo '< /pre>';

}

例如thinkphp就是這么做的,但是個人感覺太麻煩了,

如果php有個類似的內置函數,那不是方便多了?為此我們可以更改print_r的源代碼,讓他在輸出數組前先輸出pre標簽,print_r的源代碼在ext/standard/basic_functions.c中,

但是呢,修改php的原有函數畢竟不太好,我們還是新添加一個擴展好了。

我們添加一個tiyee擴展,增加一個dump()函數

代碼如下

cd /path/to/phpsource/ext

./ext_skel --extname=tiyee

cd tiyee

vi config.m4

出現如下提示

$ cd ..

$ vi ext/tiyee/config.m4

$ ./buildconf

$ ./configure --\[with|enable\]-tiyee

$ make

$ ./sapi/cli/php -f ext/tiyee/tiyee.php

$ vi ext/tiyee/tiyee.c

$ make

Repeat steps 3-6 until you are satisfied with ext/tiyee/config.m4 and

step 6 confirms that your module is compiled into PHP. Then, start writing

code and repeat the last two steps as often as necessary.

然后進入生成的文件夾,打開config.m4

cd tiyee

vi config.m4

然后,將里面的代碼里面的16-18行前面的dnl注釋去掉,即改成如下

PHP_ARG_ENABLE(tiyee, whether to enable tiyee support,

Make sure that the comment is aligned:

[ --enable-tiyee Enable tiyee support])

然后運行

phpize

生成如下提示

Configuring for:

PHP Api Version: 20121113

Zend Module Api No: 20121212

Zend Extension Api No: 220121212

打開php_tiyee.h,在PHP_FUNCTION(confirm_tiyee_compiled); /* For testing, remove later. */下面增加一行(你其實也可以直接更改它)

PHP_FUNCTION(confirm_tiyee_compiled); /* For testing, remove later. */

PHP_FUNCTION(dump);

然后打開tiyee.c,在PHP_FE(confirm_tiyee_compiled, NULL) /* For testing, remove later. */下面增加一行

改成

PHP_FE(confirm_tiyee_compiled, NULL) /* For testing, remove later. */

PHP_FE(dump, NULL)

然后下面增加具體的函數,可以在

PHP_FUNCTION(confirm_tiyee_compiled)

{

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, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "jumtao", arg);

RETURN_STRINGL(strg, len, 0);

}

增加一行,變成

PHP_FUNCTION(dump)

{

zval *var;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &var) == FAILURE) {

RETURN_FALSE;

}

printf("< pre >\n");

zend_print_zval_r(var, 0 TSRMLS\_CC);

printf("< /pre > \n");

}

PHP_FUNCTION(confirm_tiyee_compiled)

{

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, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "jumtao", arg);

RETURN_STRINGL(strg, len, 0);

}

現在我們可以編譯了

./configure --with-php-config=/usr/local/php/bin/php-config /*后面的php-config地址按你的實際地址寫*/

make

make install

然后再php.ini里添加

extension=tiyee.so

然后重啟php-fpm

試試,這時試試,是不是可以了!

總結

以上是生活随笔為你收集整理的allowedExts php,通过php扩展增加一个内置函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。