├── .gitignore ├── CREDITS ├── EXPERIMENTAL ├── README.md ├── config.m4 ├── config.w32 ├── example └── tools.php ├── php_tools.h ├── tests └── string │ ├── insert_head.phpt │ ├── insert_tail.phpt │ ├── lower.phpt │ ├── replace.phpt │ ├── substr.phpt │ ├── upper.phpt │ └── value.phpt ├── tool_string.c └── tools.c /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | *.lo 3 | *.la 4 | .libs 5 | acinclude.m4 6 | aclocal.m4 7 | autom4te.cache 8 | build 9 | config.guess 10 | config.h 11 | config.h.in 12 | config.log 13 | config.nice 14 | config.status 15 | config.sub 16 | configure 17 | configure.in 18 | include 19 | install-sh 20 | libtool 21 | ltmain.sh 22 | Makefile 23 | Makefile.fragments 24 | Makefile.global 25 | Makefile.objects 26 | missing 27 | mkinstalldirs 28 | modules 29 | run-tests.php 30 | tests/*/*.diff 31 | tests/*/*.out 32 | tests/*/*.php 33 | tests/*/*.exp 34 | tests/*/*.log 35 | tests/*/*.sh 36 | 37 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | tools -------------------------------------------------------------------------------- /EXPERIMENTAL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stable-online/tool-php-extension/a97f56c8177355c4e61f9e480045f87b8b7672f1/EXPERIMENTAL -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP tool functions 2 | This is an extension of various common tools in PHP,New fun features will be added step by step,Look forward to it!!! 3 | 4 | ## Requirement 5 | - PHP 7.0+ (PHP8 is not included)) 6 | 7 | ## Install 8 | ```shell 9 | phpize 10 | 11 | ./configure --with-php-config=/path/to/php-config 12 | 13 | make && make install 14 | 15 | echo "extension=tools.so" >> /etc/php.ini 16 | ``` 17 | ### Example: 18 | 19 | #### String Object 20 | 21 | `string object` The supplementary PHP string does not have the defect of behavior 22 | 23 | ```php 24 | substr(0,3)->value().PHP_EOL;//output:123 29 | echo $str->substr(1,3)->value().PHP_EOL;//output:23 30 | 31 | //2. replace string behavior [ replace(string search,string replace) ] 32 | $str = new String("123456ZAaa"); 33 | echo $str->replace('23',"bbb")->value().PHP_EOL;//output:1bbb456ZAaa 34 | 35 | //3. insert content to string tail behavior [ insert_tail(string tailString) ] 36 | $str = new String("123456ZAaa"); 37 | echo $str->insert_tail("--hello world")->value().PHP_EOL;//output:123456ZAaa--hello world 38 | 39 | //4. insert content to string head behavior [ insert_head(string headString) ] 40 | $str = new String("123456ZAaa"); 41 | echo $str->insert_head("--bb--")->value().PHP_EOL;//output:--bb--123456ZAaa 42 | 43 | //5. take string exchange to Lowercase character[ lower() ] 44 | $str = new String("123456ZAaa"); 45 | echo $str->lower()->value().PHP_EOL;//output:123456zaaa 46 | 47 | //6. take string exchange to Uppercase character [ upper() ] 48 | $str = new String("123456ZAaa"); 49 | echo $str->upper()->value().PHP_EOL;//output:123456ZAAA 50 | ``` 51 | 52 | ## contact 53 | e-mail: 2426594859@qq.com 54 | 55 | Welcome to join -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension tools 3 | 4 | dnl Comments in this file start with the string 'dnl'. 5 | dnl Remove where necessary. This file will not work 6 | dnl without editing. 7 | 8 | dnl If your extension references something external, use with: 9 | 10 | PHP_ARG_WITH(tools, for tools support, 11 | Make sure that the comment is aligned: 12 | [ --with-tools Include tools support]) 13 | 14 | dnl Otherwise use enable: 15 | 16 | dnl PHP_ARG_ENABLE(tools, whether to enable tools support, 17 | dnl Make sure that the comment is aligned: 18 | dnl [ --enable-tools Enable tools support]) 19 | 20 | if test "$PHP_TOOLS" != "no"; then 21 | dnl Write more examples of tests here... 22 | 23 | dnl # --with-tools -> check with-path 24 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 25 | dnl SEARCH_FOR="/include/tools.h" # you most likely want to change this 26 | dnl if test -r $PHP_TOOLS/$SEARCH_FOR; then # path given as parameter 27 | dnl TOOLS_DIR=$PHP_TOOLS 28 | dnl else # search default path list 29 | dnl AC_MSG_CHECKING([for tools files in default path]) 30 | dnl for i in $SEARCH_PATH ; do 31 | dnl if test -r $i/$SEARCH_FOR; then 32 | dnl TOOLS_DIR=$i 33 | dnl AC_MSG_RESULT(found in $i) 34 | dnl fi 35 | dnl done 36 | dnl fi 37 | dnl 38 | dnl if test -z "$TOOLS_DIR"; then 39 | dnl AC_MSG_RESULT([not found]) 40 | dnl AC_MSG_ERROR([Please reinstall the tools distribution]) 41 | dnl fi 42 | 43 | dnl # --with-tools -> add include path 44 | dnl PHP_ADD_INCLUDE($TOOLS_DIR/include) 45 | 46 | dnl # --with-tools -> check for lib and symbol presence 47 | dnl LIBNAME=tools # you may want to change this 48 | dnl LIBSYMBOL=tools # you most likely want to change this 49 | 50 | dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 51 | dnl [ 52 | dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TOOLS_DIR/$PHP_LIBDIR, TOOLS_SHARED_LIBADD) 53 | dnl AC_DEFINE(HAVE_TOOLSLIB,1,[ ]) 54 | dnl ],[ 55 | dnl AC_MSG_ERROR([wrong tools lib version or lib not found]) 56 | dnl ],[ 57 | dnl -L$TOOLS_DIR/$PHP_LIBDIR -lm 58 | dnl ]) 59 | dnl 60 | dnl PHP_SUBST(TOOLS_SHARED_LIBADD) 61 | 62 | PHP_NEW_EXTENSION(tools, tools.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) 63 | fi 64 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | // If your extension references something external, use ARG_WITH 5 | // ARG_WITH("tools", "for tools support", "no"); 6 | 7 | // Otherwise, use ARG_ENABLE 8 | // ARG_ENABLE("tools", "enable tools support", "no"); 9 | 10 | if (PHP_TOOLS != "no") { 11 | EXTENSION("tools", "tools.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /example/tools.php: -------------------------------------------------------------------------------- 1 | substr(0,3)->value().PHP_EOL;//output:123 6 | echo $str->substr(1,3)->value().PHP_EOL;//output:23 7 | 8 | //2. replace string behavior [ replace(string search,string replace) ] 9 | $str = new String("123456ZAaa"); 10 | echo $str->replace('23',"bbb")->value().PHP_EOL;//output:1bbb456ZAaa 11 | 12 | //3. insert content to string tail behavior [ insert_tail(string tailString) ] 13 | $str = new String("123456ZAaa"); 14 | echo $str->insert_tail("--hello world")->value().PHP_EOL;//output:123456ZAaa--hello world 15 | 16 | //4. insert content to string head behavior [ insert_head(string headString) ] 17 | $str = new String("123456ZAaa"); 18 | echo $str->insert_head("--bb--")->value().PHP_EOL;//output:--bb--123456ZAaa 19 | 20 | //5. take string exchange to Lowercase character[ lower() ] 21 | $str = new String("123456ZAaa"); 22 | echo $str->lower()->value().PHP_EOL;//output:123456zaaa 23 | 24 | //6. take string exchange to Uppercase character [ upper() ] 25 | $str = new String("123456ZAaa"); 26 | echo $str->upper()->value().PHP_EOL;//output:123456ZAAA -------------------------------------------------------------------------------- /php_tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2017 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_TOOLS_H 22 | /** 23 | * string class method 24 | * @param execute_data 25 | * @param return_value 26 | */ 27 | ZEND_METHOD(String,__construct); 28 | ZEND_METHOD(String,value); 29 | ZEND_METHOD(String,substr); 30 | ZEND_METHOD(String,replace); 31 | ZEND_METHOD(String,insert_tail); 32 | ZEND_METHOD(String,insert_head); 33 | ZEND_METHOD(String,lower); 34 | ZEND_METHOD(String,upper); 35 | #define PHP_TOOLS_H 36 | 37 | extern zend_module_entry tools_module_entry; 38 | #define phpext_tools_ptr &tools_module_entry 39 | 40 | #define PHP_TOOLS_VERSION "0.1.0" /* Replace with version number for your extension */ 41 | 42 | #ifdef PHP_WIN32 43 | # define PHP_TOOLS_API __declspec(dllexport) 44 | #elif defined(__GNUC__) && __GNUC__ >= 4 45 | # define PHP_TOOLS_API __attribute__ ((visibility("default"))) 46 | #else 47 | # define PHP_TOOLS_API 48 | #endif 49 | 50 | #ifdef ZTS 51 | #include "TSRM.h" 52 | #endif 53 | 54 | /* 55 | Declare any global variables you may need between the BEGIN 56 | and END macros here: 57 | 58 | ZEND_BEGIN_MODULE_GLOBALS(tools) 59 | zend_long global_value; 60 | char *global_string; 61 | ZEND_END_MODULE_GLOBALS(tools) 62 | */ 63 | 64 | /* Always refer to the globals in your function as TOOLS_G(variable). 65 | You are encouraged to rename these macros something shorter, see 66 | examples in any other php module directory. 67 | */ 68 | #define TOOLS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(tools, v) 69 | 70 | #if defined(ZTS) && defined(COMPILE_DL_TOOLS) 71 | ZEND_TSRMLS_CACHE_EXTERN() 72 | #endif 73 | 74 | #endif /* PHP_TOOLS_H */ 75 | 76 | 77 | /* 78 | * Local variables: 79 | * tab-width: 4 80 | * c-basic-offset: 4 81 | * End: 82 | * vim600: noet sw=4 ts=4 fdm=marker 83 | * vim<600: noet sw=4 ts=4 84 | */ 85 | -------------------------------------------------------------------------------- /tests/string/insert_head.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | insert_head("hello--")->value(); 9 | ?> 10 | --EXPECT-- 11 | hello--123456ZAaa -------------------------------------------------------------------------------- /tests/string/insert_tail.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | insert_tail("--hello")->value(); 9 | ?> 10 | --EXPECT-- 11 | 123456ZAaa--hello -------------------------------------------------------------------------------- /tests/string/lower.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | lower()->value(); 9 | ?> 10 | --EXPECT-- 11 | 123456zaaa -------------------------------------------------------------------------------- /tests/string/replace.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | replace(1,3)->value(); 9 | ?> 10 | --EXPECT-- 11 | 323456ZAaa -------------------------------------------------------------------------------- /tests/string/substr.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | substr(0,3)->value(); 9 | ?> 10 | --EXPECT-- 11 | 123 -------------------------------------------------------------------------------- /tests/string/upper.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | upper()->value(); 9 | ?> 10 | --EXPECT-- 11 | 123456ZAAA -------------------------------------------------------------------------------- /tests/string/value.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tools presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | value(); 9 | ?> 10 | --EXPECT-- 11 | 123456ZAaa -------------------------------------------------------------------------------- /tool_string.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhaowei on 2022/1/26. 3 | // 4 | 5 | #include "php.h" 6 | #include "php_ini.h" 7 | #include "ext/standard/info.h" 8 | #include "php_tools.h" 9 | #include "ext/standard/php_string.h" 10 | 11 | /** 12 | * take string exchange to uppercase character 13 | * @param execute_data 14 | * @param return_value 15 | */ 16 | zend_string *strtoupper(zval *pStruct); 17 | 18 | /** 19 | * 转化字符串 20 | * @param pStruct 21 | * @return 22 | */ 23 | zend_string *strtoupper(zval *pStruct) { 24 | zend_string *string = zval_get_string(pStruct); 25 | zval strtoupper,c_ret_2, param[1]; 26 | ZVAL_STRING(¶m[0], string->val); 27 | ZVAL_STRING(&strtoupper, "strtoupper"); 28 | if (call_user_function(NULL, NULL, &strtoupper, &c_ret_2, 1, param) == FAILURE) { 29 | php_printf("error{1}"); 30 | } 31 | zval_dtor(&strtoupper); 32 | zval_dtor(¶m[0]); 33 | zend_string *pString = zval_get_string(&c_ret_2); 34 | zval_dtor(&c_ret_2); 35 | return pString; 36 | } 37 | 38 | /** 39 | * take string exchange to Lowercase character 40 | * @param execute_data 41 | * @param return_value 42 | */ 43 | zend_string *strtolower(const zend_string *string); 44 | 45 | 46 | zend_string *strtolower(const zend_string *string) { 47 | zval strtolower, c_ret_2, param[1]; 48 | ZVAL_STRING(¶m[0], string->val); 49 | ZVAL_STRING(&strtolower, "strtolower"); 50 | 51 | if (call_user_function(NULL, NULL, &strtolower, &c_ret_2, 1, param) == FAILURE) { 52 | php_printf("error{1}"); 53 | } 54 | 55 | zval_dtor(&strtolower); 56 | zval_dtor(¶m[0]); 57 | zend_string *pString = zval_get_string(&c_ret_2); 58 | zval_dtor(&c_ret_2); 59 | return pString; 60 | } 61 | 62 | /** 63 | * string replace behavior 64 | * @param execute_data 65 | * @param return_value 66 | */ 67 | zend_string *str_replace(const zend_string *search, const zend_string *replace, const zend_string *string); 68 | 69 | 70 | zend_string *str_replace(const zend_string *search, const zend_string *replace, const zend_string *string) { 71 | zval substr, c_ret_2, param[3]; 72 | ZVAL_STRING(¶m[0], search->val); 73 | ZVAL_STRING(¶m[1], replace->val); 74 | ZVAL_STRING(¶m[2], string->val); 75 | ZVAL_STRING(&substr, "str_replace"); 76 | 77 | if (call_user_function(NULL, NULL, &substr, &c_ret_2, 3, param) == FAILURE) { 78 | php_printf("error{1}"); 79 | } 80 | zval_dtor(&substr); 81 | zval_dtor(¶m[0]); 82 | zval_dtor(¶m[1]); 83 | zval_dtor(¶m[2]); 84 | zend_string *pString = zval_get_string(&c_ret_2); 85 | zval_dtor(&c_ret_2); 86 | return pString; 87 | } 88 | 89 | 90 | /** 91 | * string append behavior 92 | * @param execute_data 93 | * @param return_value 94 | */ 95 | zend_string *insert_tail( zend_string *user_string, zval *pStruct); 96 | 97 | zend_string *insert_tail( zend_string *user_string, zval *pStruct) { 98 | zend_string *string = zval_get_string(pStruct); 99 | zval_dtor(pStruct); 100 | zend_string *pString = strpprintf(0, "%s%s", string->val, user_string->val); 101 | return pString; 102 | } 103 | 104 | 105 | /** 106 | * insert head behavior 107 | * @param execute_data 108 | * @param return_value 109 | */ 110 | zend_string *insert_head(const zend_string *user_string, const zend_string *string); 111 | 112 | 113 | zend_string *insert_head(const zend_string *user_string, const zend_string *string) { 114 | zval substr, c_ret_2, param[3]; 115 | zend_string *pString = strpprintf(0, "%s%s", user_string->val, string->val); 116 | return pString; 117 | } 118 | 119 | /** 120 | * string substr behavior 121 | * @param execute_data 122 | * @param return_value 123 | */ 124 | zend_string *substr(zend_long start, zend_long end, const zend_string *string); 125 | 126 | 127 | zend_string *substr(zend_long start, zend_long end, const zend_string *string) { 128 | zval substr, c_ret_2, param[3]; 129 | ZVAL_STRING(¶m[0], string->val); 130 | ZVAL_LONG(¶m[1], start); 131 | ZVAL_LONG(¶m[2], end); 132 | ZVAL_STRING(&substr, "substr"); 133 | if (call_user_function(NULL, NULL, &substr, &c_ret_2, 3, param) == FAILURE) { 134 | php_printf("error{1}"); 135 | } 136 | 137 | zval_dtor(&substr); 138 | zval_dtor(¶m[0]); 139 | zval_dtor(¶m[1]); 140 | zval_dtor(¶m[2]); 141 | zend_string *pString = zval_get_string(&c_ret_2); 142 | zval_dtor(&c_ret_2); 143 | return pString; 144 | } -------------------------------------------------------------------------------- /tools.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2017 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: zhaowei 16 | | email: 2426595849@qq.com 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include "php.h" 27 | #include "php_ini.h" 28 | #include "ext/standard/info.h" 29 | #include "php_tools.h" 30 | #include "ext/standard/php_string.h" 31 | #include "tool_string.c" 32 | 33 | /* {{{ PHP_INI 34 | */ 35 | /* Remove comments and fill if you need to have entries in php.ini 36 | PHP_INI_BEGIN() 37 | STD_PHP_INI_ENTRY("tools.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_tools_globals, tools_globals) 38 | STD_PHP_INI_ENTRY("tools.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_tools_globals, tools_globals) 39 | PHP_INI_END() 40 | */ 41 | /* }}} */ 42 | 43 | /* Remove the following function when you have successfully modified config.m4 44 | so that your module can be compiled into PHP, it exists only for testing 45 | purposes. */ 46 | 47 | /* The previous line is meant for vim and emacs, so it can correctly fold and 48 | unfold functions in source code. See the corresponding marks just before 49 | function definition, where the functions purpose is also documented. Please 50 | follow this convention for the convenience of others editing your code. 51 | */ 52 | 53 | 54 | /* {{{ php_tools_init_globals 55 | */ 56 | /* Uncomment this function if you have INI entries 57 | static void php_tools_init_globals(zend_tools_globals *tools_globals) 58 | { 59 | tools_globals->global_value = 0; 60 | tools_globals->global_string = NULL; 61 | } 62 | */ 63 | /* }}} */ 64 | zend_function_entry string_function[] = { 65 | ZEND_ME(String, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 66 | ZEND_ME(String, value, NULL, ZEND_ACC_PUBLIC) 67 | ZEND_ME(String, substr, NULL, ZEND_ACC_PUBLIC) 68 | ZEND_ME(String, replace, NULL, ZEND_ACC_PUBLIC) 69 | ZEND_ME(String, insert_tail, NULL, ZEND_ACC_PUBLIC) 70 | ZEND_ME(String, insert_head, NULL, ZEND_ACC_PUBLIC) 71 | ZEND_ME(String, lower, NULL, ZEND_ACC_PUBLIC) 72 | ZEND_ME(String, upper, NULL, ZEND_ACC_PUBLIC) 73 | ZEND_FE_END 74 | }; 75 | 76 | 77 | zend_class_entry *String_Object_Tools; 78 | 79 | ZEND_METHOD(String, upper){ 80 | zval rv; 81 | zend_class_entry *ce; 82 | ce = Z_OBJCE_P(getThis()); 83 | zval c_ret, constructor, parameter ; 84 | zval *pStructProperty = zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv); 85 | 86 | zend_string *pString = strtoupper(pStructProperty); 87 | 88 | zval_dtor(pStructProperty); 89 | zend_update_property_string(ce, getThis(), "property", strlen("property"), pString->val TSRMLS_CC); 90 | 91 | efree(pString); 92 | RETURN_OBJ(zend_objects_clone_obj(getThis())); 93 | } 94 | 95 | ZEND_METHOD(String, lower){ 96 | zval rv; 97 | zend_class_entry *ce; 98 | ce = Z_OBJCE_P(getThis()); 99 | zval c_ret, constructor, parameter; 100 | 101 | zval *pStruct = zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv); 102 | zend_string *string = zval_get_string(pStruct); 103 | zval_dtor(pStruct); 104 | 105 | zend_string *pString = strtolower(string); 106 | zend_update_property_string(ce, getThis(), "property", strlen("property"), pString->val TSRMLS_CC); 107 | 108 | efree(pString); 109 | RETURN_OBJ(zend_objects_clone_obj(getThis())); 110 | } 111 | 112 | /** 113 | * __construct 114 | * @param execute_data 115 | * @param return_value 116 | */ 117 | ZEND_METHOD(String, __construct) { 118 | zval *string; 119 | int len; 120 | 121 | ZEND_PARSE_PARAMETERS_START(1, 1); 122 | Z_PARAM_ZVAL(string); 123 | ZEND_PARSE_PARAMETERS_END(); 124 | 125 | if (Z_TYPE_P(string) != IS_STRING) { 126 | php_error_docref(NULL, E_ERROR, "parameter must is string"); 127 | RETURN_FALSE; 128 | } 129 | 130 | zend_update_property_string(String_Object_Tools, getThis(), "property", strlen("property"), Z_STRVAL_P(string)); 131 | } 132 | 133 | /** 134 | * print string 135 | * @param execute_data 136 | * @param return_value 137 | */ 138 | ZEND_METHOD(String, value) { 139 | zval *msg, rv; 140 | zval *object = getThis(); 141 | 142 | zend_class_entry *ce; 143 | ce = Z_OBJCE_P(getThis()); 144 | zend_string *string = zval_get_string(zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv)); 145 | 146 | RETURN_STR(string); 147 | } 148 | 149 | ZEND_METHOD(String, replace){ 150 | 151 | zend_string *search; 152 | zend_string *replace; 153 | zval rv; 154 | zend_class_entry *ce; 155 | ce = Z_OBJCE_P(getThis()); 156 | zval c_ret, constructor, parameter; 157 | 158 | ZEND_PARSE_PARAMETERS_START(2, 2) 159 | Z_PARAM_STR(search) 160 | Z_PARAM_STR(replace) 161 | ZEND_PARSE_PARAMETERS_END(); 162 | 163 | zval *pStructProperty = zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv); 164 | zend_string *string = zval_get_string(pStructProperty); 165 | zval_dtor(pStructProperty); 166 | 167 | zend_string *pString = str_replace(search, replace, string); 168 | zend_update_property_string(ce, getThis(), "property", strlen("property"), pString->val TSRMLS_CC); 169 | efree(pString); 170 | 171 | RETURN_OBJ(zend_objects_clone_obj(getThis())); 172 | } 173 | 174 | ZEND_METHOD(String, insert_tail){ 175 | 176 | zend_string *user_string; 177 | 178 | zval rv; 179 | zend_class_entry *ce; 180 | ce = Z_OBJCE_P(getThis()); 181 | zval c_ret, constructor, parameter; 182 | 183 | ZEND_PARSE_PARAMETERS_START(1, 1) 184 | Z_PARAM_STR(user_string) 185 | ZEND_PARSE_PARAMETERS_END(); 186 | 187 | zval substr, c_ret_2, param[3]; 188 | zval *pStruct = zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv); 189 | 190 | zend_string *pString = insert_tail(user_string, pStruct); 191 | 192 | zend_update_property_string(ce, getThis(), "property", strlen("property"), pString->val TSRMLS_CC); 193 | efree(pString); 194 | RETURN_OBJ(zend_objects_clone_obj(getThis())); 195 | } 196 | 197 | ZEND_METHOD(String, insert_head) 198 | { 199 | zend_string *user_string; 200 | 201 | zval rv; 202 | zend_class_entry *ce; 203 | ce = Z_OBJCE_P(getThis()); 204 | zval c_ret, constructor, parameter; 205 | 206 | ZEND_PARSE_PARAMETERS_START(1, 1) 207 | Z_PARAM_STR(user_string) 208 | ZEND_PARSE_PARAMETERS_END(); 209 | 210 | zval *pStruct = zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv); 211 | zend_string *string = zval_get_string(pStruct); 212 | zval_dtor(pStruct); 213 | 214 | zend_string *pString = insert_head(user_string, string); 215 | 216 | zend_update_property_string(ce, getThis(), "property", strlen("property"), pString->val TSRMLS_CC); 217 | efree(pString); 218 | RETURN_OBJ(zend_objects_clone_obj(getThis())); 219 | } 220 | 221 | ZEND_METHOD(String, substr) 222 | { 223 | zend_long start; 224 | zend_long end; 225 | zval rv; 226 | zend_class_entry *ce; 227 | ce = Z_OBJCE_P(getThis()); 228 | zval c_ret, constructor, parameter; 229 | 230 | ZEND_PARSE_PARAMETERS_START(1, 2); 231 | Z_PARAM_LONG(start) 232 | Z_PARAM_OPTIONAL 233 | Z_PARAM_LONG(end) 234 | ZEND_PARSE_PARAMETERS_END(); 235 | 236 | zval *pStruct = zend_read_property(ce, getThis(), "property", strlen("property"), 1, &rv); 237 | zend_string *string = zval_get_string(pStruct); 238 | zval_dtor(pStruct); 239 | 240 | zend_string *pString = substr(start, end, string); 241 | 242 | zend_update_property_string(ce, getThis(), "property", strlen("property"), pString->val TSRMLS_CC); 243 | 244 | efree(pString); 245 | RETURN_OBJ(zend_objects_clone_obj(getThis())); 246 | } 247 | 248 | /* {{{ PHP_MINIT_FUNCTION 249 | */ 250 | PHP_MINIT_FUNCTION (tools) { 251 | //String tools 252 | zend_class_entry String_Object; 253 | INIT_CLASS_ENTRY(String_Object, "String", string_function); 254 | String_Object_Tools = zend_register_internal_class(&String_Object); 255 | zend_declare_property_string(String_Object_Tools, "property", strlen("property"), "", ZEND_ACC_PRIVATE); 256 | 257 | return SUCCESS; 258 | } 259 | /* }}} */ 260 | 261 | /* {{{ PHP_MSHUTDOWN_FUNCTION 262 | */ 263 | PHP_MSHUTDOWN_FUNCTION (tools) { 264 | /* uncomment this line if you have INI entries 265 | UNREGISTER_INI_ENTRIES(); 266 | */ 267 | return SUCCESS; 268 | } 269 | /* }}} */ 270 | 271 | /* Remove if there's nothing to do at request start */ 272 | /* {{{ PHP_RINIT_FUNCTION 273 | */ 274 | PHP_RINIT_FUNCTION (tools) { 275 | #if defined(COMPILE_DL_TOOLS) && defined(ZTS) 276 | ZEND_TSRMLS_CACHE_UPDATE(); 277 | #endif 278 | return SUCCESS; 279 | } 280 | /* }}} */ 281 | 282 | /* Remove if there's nothing to do at request end */ 283 | /* {{{ PHP_RSHUTDOWN_FUNCTION 284 | */ 285 | PHP_RSHUTDOWN_FUNCTION (tools) { 286 | return SUCCESS; 287 | } 288 | /* }}} */ 289 | 290 | /* {{{ PHP_MINFO_FUNCTION 291 | */ 292 | PHP_MINFO_FUNCTION (tools) { 293 | php_info_print_table_start(); 294 | php_info_print_table_header(2, "tools support", "enabled"); 295 | php_info_print_table_end(); 296 | 297 | /* Remove comments if you have entries in php.ini 298 | DISPLAY_INI_ENTRIES(); 299 | */ 300 | } 301 | /* }}} */ 302 | 303 | /* {{{ tools_functions[] 304 | * 305 | * Every user visible function must have an entry in tools_functions[]. 306 | */ 307 | const zend_function_entry tools_functions[] = { 308 | PHP_FE_END /* Must be the last line in tools_functions[] */ 309 | }; 310 | /* }}} */ 311 | 312 | /* {{{ tools_module_entry 313 | */ 314 | zend_module_entry tools_module_entry = { 315 | STANDARD_MODULE_HEADER, 316 | "tools", 317 | tools_functions, 318 | PHP_MINIT(tools), 319 | PHP_MSHUTDOWN(tools), 320 | PHP_RINIT(tools), /* Replace with NULL if there's nothing to do at request start */ 321 | PHP_RSHUTDOWN(tools), /* Replace with NULL if there's nothing to do at request end */ 322 | PHP_MINFO(tools), 323 | PHP_TOOLS_VERSION, 324 | STANDARD_MODULE_PROPERTIES 325 | }; 326 | /* }}} */ 327 | 328 | #ifdef COMPILE_DL_TOOLS 329 | #ifdef ZTS 330 | ZEND_TSRMLS_CACHE_DEFINE() 331 | #endif 332 | ZEND_GET_MODULE(tools) 333 | #endif 334 | 335 | /* 336 | * Local variables: 337 | * tab-width: 4 338 | * c-basic-offset: 4 339 | * End: 340 | * vim600: noet sw=4 ts=4 fdm=marker 341 | * vim<600: noet sw=4 ts=4 342 | */ 343 | --------------------------------------------------------------------------------