|
Posted by Joachim Weiß on 08/29/05 01:27
<- Chameleon -> schrieb:
> I want to run PHP scripts from my C++ program.
> I can run "php -n my_script.php" but I have 2 problems:
>
how about sth like this:
2 cplusprogs and a php file make the world.
I hope it helps
Jo
example:
hello.cc:
#include <iostream>
using namespace std;
int main(int argc,char **argP) {
cout << "Hello ";
return(0);
}
world.php:
#!/opt/lampp/bin/php -q
<?php
if(!defined("STDIN")) {
define("STDIN", fopen('php://stdin','r'));
}
if(!defined("STDOUT")) {
define("STDOUT", fopen('php://stdout','w'));
}
$in =fread(STDIN,1024);
$out="$in World";
fwrite(STDOUT,$out);
fflush(STDOUT);
die(0);
?>
endWord.cc:
#include <iostream>
using namespace std;
int main(int argc,char **argv) {
char in[1024];
cin.get(in,1023);
cout << in << "!\n";
return(0);
}
../hello | ./world.php | ./endWorld
prints:
Hello World!
Navigation:
[Reply to this message]
|