Call the C function with PHP, often implemented by calling the system command function, there are two kinds of system () and exec (), and there is a passthru (), this method has no attempt, not discussing.
The system () method outputs and returns the last line's shell result.
EXEC () does not output the result, returns the last line shell result, all results can be saved to a returned array.
The same point is that the status code executed by the command can be obtained.
PHP call C function method is:
If the C function is a simple Hello World, the file name is Hello.c.
#include
Main ()
{
PRINTF ("Hello World!");
}
Note: If multi-line output is used to use "
" Do not "\ n"
First, GCC compile to GCC Hello.c -o Hello
Then write a function in the PHP function:
PHP
$ r = exec ("./ Hello");
Echo $ R;
?>
If it is exec, if the result is performed in the browser, there will be 1 Hello World (Echo $ R). If you call it with system, two Hello World! (./ Hello and Echo $ R) will appear. ).
Of course, you can also implement PHP call C functions in a way!