0

I am trying to create php extension in which I pass string, int, char to my .cpp file. My zend function in .cpp file is like this:

#define PHP_COMPILER_ID  "VC9"

#include "php.h"


ZEND_FUNCTION(use_html);

zend_function_entry use_functions[] = 
{
    ZEND_FE(use_html, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry use_html_module_entry = 
{
    STANDARD_MODULE_HEADER,
    "Use Html",
    use_functions,
    NULL, NULL, NULL, NULL, NULL,
    "1.0.0-tutorial",
    STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(use_html);

ZEND_FUNCTION(use_html)
{
     int useHtml;
     char *ch;
     int a=10,b=120,c;
     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "/", &useHtml) == FAILURE)
     {
         E_ERROR;
         return;
     }
     c=a+b;
     php_printf("sum is",&useHtml);
     php_printf("This string  is %d :" +  useHtml );
     if(useHtml==1)
     {
         php_printf("\n This string uses <a href='#'>Html</a>");
     }
     else
     {
         php_printf("This string does not Html");
     }

     return;
}

and php code:

<?php

use_html(1);
//use_html("hi"); for string passing
?>

But this does not work. How to pass from php and how to print in zend function?

Error is like this:

( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: use_html() expects parameter 1 to be unknown, integer given in D:\wamp\www\test.php on line 3
Call Stack
#   Time    Memory  Function    Location
1   0.0006  138008  {main}( )   ..\test.php:0
2   0.0006  138352  use_html ( )    ..\test.php:3
4

1 回答 1

0

在这部分:

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "/", &useHtml) == FAILURE)

您必须指定“/”所在的预期参数类型。要接受每种类型,您可以使用“z”。但是请查看README.PARAMETER_PARSING_API 文件,因此要访问 char*、long、double 值,您必须使用宏或将值转换为字符串,如需查看文档

于 2013-06-22T13:55:16.433 回答