PHPtoCpp it is a simple transpiler that transforms your PHP file to C++ file.
$ git clone https://github.com/antonyalkmim/PHPtoCpp
$ cd PHPtoCpp
$ cmake CMakeLists.txt
$ make
$ PHPtoCpp index.php
Will generate a index.php.cpp
file.
PHP infile( index.php
):
<?php
$foo = $_POST['foo'] ; //string
$bar = 1 + 2 ; //int
if ( $foo ) {
$fb = $bar ; //int
echo $fb ;
}
?>
C++ outfile (index.php.cpp
):
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
string foo;
cin >> foo;
int bar = 1 + 2 ;
if ( foo ) {
int fb = bar ;
cout << fb ;
}
}
- It is converting only sequencial and simple PHP commands
- All tokens should be separeted by a single space
if ( true ) { ... }
- Datatypes should be declared in the final of variable declaration the line:
- Ex:
$foo = 1 ; //int
- Datatypes:
//int
,//float
,//double
,//bool
,//string
- Ex:
- Input data has to be:
$_REQUEST['name']
,$_POST['name']
or$_GET['name']
, Example:$data = $_POST['data'] ; //string
will be convert tostring data; cin >> data;
- It is included unecessary c++ libraries when converts.
- Variable names should be more then one character:
$a = 1 ; // segmentation error
$aa = 1 ; // convert normally
WTFPL
It's free