Вот пример на C под Unix:
Код | /* включить/include стандартный header */
#include <php.h> #include <file.h> #include "my_pcre.c"
#include <stdlib.h> #include <string.h> #include <ctype.h> #include <sys/types.h>
#include "url.h" #ifdef _OSD_POSIX #ifndef APACHE #error On this EBCDIC platform, PHP is only supported as an Apache module. #else /*APACHE*/ #ifndef CHARSET_EBCDIC #define CHARSET_EBCDIC /* this machine uses EBCDIC, not ASCII! */ #endif #include "ebcdic.h" #endif /*APACHE*/ #endif /*_OSD_POSIX*/ static char hexchars[] = "0123456789abcdef"; static char HEXCHARS[] = "0123456789ABCDEF";
//#include <stdio.h>
/* объявление экспортируемой функции */ ZEND_FUNCTION(f1);
/* скомпилированный список функций, так что Zend знает, что находится в этом модуле */ zend_function_entry mod1_functions[] = { ZEND_FE(f1, NULL) {NULL, NULL, NULL} };
/* скомпилированная информация модуля */ zend_module_entry mod1_module_entry = { STANDARD_MODULE_HEADER, "Module 1", mod1_functions, NULL, NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES };
/* реализуется стандартная "заглушка/stub" для введения в Zend */ #if COMPILE_DL_MOD1 ZEND_GET_MODULE(mod1) #endif
PHPAPI char *php_url_encode(char const *s, int len, int *new_length) { register unsigned char c; unsigned char *to, *start; unsigned char const *from, *end; from = s; end = s + len; start = to = (unsigned char *) safe_emalloc(3, len, 1);
while (from < end) { c = *from++;
if (c == ' ') { *to++ = '+'; #ifndef CHARSET_EBCDIC } else if ((c < '0' && c != '-' && c != '.') || (c < 'A' && c > '9') || (c > 'Z' && c < 'a' && c != '_') || (c > 'z')) { to[0] = '%'; to[1] = hexchars[c >> 4]; to[2] = hexchars[c & 15]; to += 3; #else /*CHARSET_EBCDIC*/ } else if (!isalnum(c) && strchr("_-.", c) == NULL) { /* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */ to[0] = '%'; to[1] = hexchars[os_toascii[c] >> 4]; to[2] = hexchars[os_toascii[c] & 15]; to += 3; #endif /*CHARSET_EBCDIC*/ } else { *to++ = c; } } *to = 0; if (new_length) { *new_length = to - start; } return (char *) start; }
char *url_encode(char *in_str) { int in_str_len,out_str_len; in_str_len=strlen(in_str);
return php_url_encode(in_str, in_str_len, &out_str_len); }
char *file_get_contents(char *filename) { /* Реализация функции */ } int main_func(long search_type,long max_pages,char *site,char *word, char match[]) { /* Реализация функции */ }
/* реализуется функция, которая должна стать доступной для PHP */ ZEND_FUNCTION(f1) { int p1,p2; int position; long search_type,max_pages; int i,j,k; char res[10]; char *res_out; char match[80]; char *site; char *word; if (zend_parse_parameters(/*ZEND_NUM_ARGS()*/4 TSRMLS_CC, "llss",&search_type,&max_pages, &site ,&p1,&word,&p2) == FAILURE) { return ; } i=main_func(search_type,max_pages,site, word, match); if (i>0) position=atoi(match); else position=0; RETURN_LONG((long)position ); //RETVAL_STRINGL( res_out,strlen(res_out),0); }
|
Искать можно http://www.google.ru/search?hl=ru&q=ZEND_FUNCTION и http://www.google.ru/search?aq=f&complete=1&hl=ru&newwindow=1&q=PHP+Creating+Extensions&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA&lr=
Добавлено через 1 минуту и 37 секунд Странно раньше на php.net еще статья была, сейчас что-то найти не могу... |