cCode:
void main(){
printf("line1\n");
printf("$var=2\n");
}
index.php
exec("./cCode", $output);
echo $output[2];
?>
As you'd expect, the php outputs the string: $var=2
However, what is the simplest way of returning variables from C to become variables in php? Json encoding perhaps? Does php and/or C have any means to easily pass or convert variable name and value pairs?
Many thanks.
My Answer:
"Hello from C!\n");
// Passing variables to PHP
int num1 = 10;
int num2 = 20;
char str[] = "Hello from C!";
char command[100];
sprintf(command, "php -r '$_num1=%d; $_num2=%d; $_str=\"%s\"; include(\"script.php\");'", num1, num2, str);
system(command);
}
Rate this post
3 of 5 based on 8730 votesComments