Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > PHP: Общие вопросы > Свои extensions в PHP


Автор: Хрипа 29.2.2008, 18:16
Документация 
Желательно исходники!
Компонеты
Спасибо!

Автор: flashaa 29.2.2008, 18:26
Думаю можно, в Делфи ведь делаются DLL - библиотеки. Полагаю, написать функции, запихать в DLL. Подключить полученный DLL как расширение extension=my.dll. Потом функции из dll-ки должны стать доступны в PHP. Только вот DLL-должна быть написана с ориентировкой на PHP. Как именно - не знаю. Да, и работать будет только под виндой, соответственно.

Автор: mishaSL 29.2.2008, 19:06
Вот пример на 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 еще статья была, сейчас что-то найти не могу...

Автор: Хрипа 29.2.2008, 20:28
mishaSL, Спасибо но в данном случаи интересует Win32 платформа )

Автор: FractalizeR 8.3.2008, 16:45
А вот как писать расширения на Delphi: http://users.telenet.be/ws36637/php4delphi.html

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)