当我们在php中使用zend函数时,如何传递string、int、char并打印它们


How to pass string,int,char and print them when we are using zend function in php?

我正在尝试创建php扩展,在该扩展中,我将字符串、int、char传递到.cpp文件。.cpp文件中的zend函数如下所示:

#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;
}

和php代码:

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

但这不起作用。如何从php传递以及如何在zend函数中打印

错误如下:

( ! ) 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

关于此部分:

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

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