PHP with C++

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Youness
Forum Newbie
Posts: 2
Joined: Tue Jun 15, 2004 4:44 am

PHP with C++

Post by Youness »

Hello,
I am trying to use a php interface to call an executable compiled in C++.
I first succeeded in using the executable’s functions and store my results in text file.
Now I am trying to use only the memory models instead of files to manipulate my actions and results with my classes, but I don’t now how to figure out with. Any help would be welcome:

My php script is :

Code: Select all

<?
//&op, &ent1, &ent2 are my variables putted in text zone in an html page
$op = $_POST['ComponantName'];
$ent1=$_POST['Diametre'];
$ent2=$_POST['Long'];
$handle = popen('fonction','w');
$contenu = "$op $ent1 $ent2";
//Fonction utilisé pour l'ecriture du flux
fwrite($handle, $contenu);
//Fonction utilisé pour la lecture du flux
echo "L'écriture de $contenu dans le fichier a réussi <br>";
pclose($handle);
?>
The C++ Classe :

Code: Select all

class Componant  
&#123;
int Diametre;
int Long;
public:
Componant();
virtual ~Componant();
&#125;; 

The constructor: 

Componant::Componant(int D, int L)
&#123;
Diametre = D;
Long= L;
&#125;

I use a function to create an instance of my class with the desired values :
void AddComponant(char name, int D, int L)
&#123;
new Componant MyComponant = Componant(name,D,L);	
&#125;
Thinks !!!

feyd|use

Code: Select all

and

Code: Select all

tags.[/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

added php tags

Code: Select all

&lt;?php
&lt;? 
//&amp;op, &amp;ent1, &amp;ent2 are my variables putted in text zone in an html page 
$op = $_POST&#1111;'ComponantName']; 
$ent1=$_POST&#1111;'Diametre']; 
$ent2=$_POST&#1111;'Long']; 
$handle = popen('fonction','w'); 
$contenu = "$op $ent1 $ent2"; 
//Fonction utilisé pour l'ecriture du flux 
fwrite($handle, $contenu); 
//Fonction utilisé pour la lecture du flux 
echo "L'écriture de $contenu dans le fichier a réussi &lt;br&gt;"; 
pclose($handle); 
?&gt; 

The C++ Classe : 

class Componant 
{ 
int Diametre; 
int Long; 
public: 
Componant(); 
virtual ~Componant(); 
}; 

The constructor: 

Componant::Componant(int D, int L) 
{ 
Diametre = D; 
Long= L; 
} 

I use a function to create an instance of my class with the desired values : 
void AddComponant(char name, int D, int L) 
{ 
new Componant MyComponant = Componant(name,D,L); 
} 

Thinks !!! 
?&gt;
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

in your c++ program you have to read the values from stdin, something like this:

Code: Select all

char&#1111;] name;
  int d;
  int l;
  name<<stdin;
  d<<stdin;
  l<<stdin;
Youness
Forum Newbie
Posts: 2
Joined: Tue Jun 15, 2004 4:44 am

PHP with C++

Post by Youness »

Is it possible to create a link (API calling) between php script and a c++ code without creating a switch on the method in the c++ code ?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

via [php_man]com[/php_man] or [php_man]w32api[/php_man] (which is completely broken in PHP4). There's also php_ffi extension mentioned in user comments on w32api manual page.
Post Reply