i want to create an extension for php with visual studio 2010 , i am beginner in c++.
my last function in C++ is :
PHP_FUNCTION(DoubleUp){
char* text;
int len;
char string[255];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &text) == FAILURE) {
RETURN_STRING("Invalid Parameters",true);
}
len = sprintf(string,"echo 'hello %.78s'", text);
RETURN_STRINGL(string,len, 1);
}
and in php i use :
echo DoubleUp('sss');
but output is : echo 'hello Ыõ'
that should be : echo 'hello sss'
argument is a very long string .
now i don’t know what should i do .
thanks …
The problem with your code is, that
zend_parse_parametersreturns azvalif you specify"z"in the “type specifier” (the third parameter ofzend_parse_parameters).To get the correct string you can get the string directly using “s”:
In that case you have to supply the pointer to the
char*for the string plus a pointer to anintto hold the string length.The second solution is to use the
zvalcorrectly and get the string out of thezval: