Apr 21, 2012 at 6:41am UTC
Below is a simple PHP code generator using C++.
www.vigshakri.com
#include <stdio>
#include <iostream>
#include <fstream>
#include <string>
//THIS PROGRAM DEMONSTRATE SIMPLE PHP CODE GENERATOR.
using namespace std;
string cars[100][100];
int row;
inline string echo(string str)
{
return "echo '" + str +"'; \n";
}
inline string messagefont(string message, char color[100])
{
string msg;
msg = "<font color=";
msg = msg + color;
msg = msg + ">";
msg = msg + message;
msg = msg + "</font> <br>";
return msg;
}
inline string tS()
{
string s;
char a;
a = 60;
s = a;
s = s + "?php ";
s = s + "\n";
return s;
}
inline string tE()
{
string s;
char b;
b = 62;
s = s + "\n";
s = s + "?";
s = s + b;
return s;
}
inline string ForLoop(string loopFrom, string loopTill, string vMessage )
{
string s;
s = "for($i=" + loopFrom + "; $i<= " + loopTill + "; $i++ ) { \n";
s = s + " \t echo '" + vMessage + "'; \n } \n\n";
return s;
}
inline string WhileLoop(string loopTill, string vMessage )
{
string s;
s = "while($i <=" + loopTill + ") { \n";
s = s + " \t echo '" + vMessage + "'; $i++; \n } \n\n";
return s;
}
inline string DoWhileLoop(string loopTill, string vMessage )
{
string s;
s = "do\n{ \n \t echo '" + vMessage + "'; $i++; \n}";
s = s + "while($i <=" + loopTill + "); \n\n";
return s;
}
inline string Table(char row[100], string column, string vMessage[100][100], int noofcol, int noofrow )
{
string setArray;
setArray = "$array = array( ";
for(int i=0; i<noofrow; i++){
setArray = setArray + "array( ";
for(int j=0; j<noofcol; j++){
cout<<vMessage[i][j]<<"\n";
if(j <= noofcol-1){
setArray = setArray + "'" + vMessage[i][j] + "', ";
}else {
setArray = setArray + "'" + vMessage[i][j] + "' ";;
}
}
setArray = setArray + "), \n";
}
setArray = setArray + " ); \n";
string tbl;
tbl = setArray;
tbl = tbl + "echo '<center><table border=1> '; \n";
tbl = tbl + "for($i=0; $i<" + row + "; $i++ ) \n { \n";
tbl = tbl + " \t echo '<tr>'; \n";
tbl = tbl + " \t for($j=0; $j<= " + column + "; $j++ ) \n\t{ \n";
tbl = tbl + " \t\t echo '<td>' .$array[$i][$j] .'</td>'; \n\t} \n";
tbl = tbl + " \t echo '</tr>'; \n } \n";
tbl = tbl + "echo '</table><center> '; \n";
return tbl;
}
void insertdata(string id, string nam, string col, string mod, string reg, string capacity)
{
cars[row][0] = id;
cars[row][1] = nam;
cars[row][2] = col;
cars[row][3] = mod;
cars[row][4] = reg;
cars[row][5] = capacity;
row++;
}
int main()
{
string s;
char message[10000];
char color[100];
string msg;
row = 0;
fstream file_ops("C:\\Program Files\\EasyPHP-5.3.2\\www\\Ctest\\home.php",ios::out);
s = tS();
s = s + " echo'Hello World <br>'; \n for($i=0; $i<=2; $i++) \n { \t echo 'Hello World <br>'; \n } \n";
s = s + echo("<br>");
cout<<"Key in the emessage for display : ";
cin.getline(message,10000);
cout<<"Key in the color for display (red, blue, yellow, green...) : ";
cin.getline(color,100);
insertdata("1","HONDA", "BLUE", "CIVIC", "WWW001", "2000");
insertdata("2","TOYOTA", "GREEN", "HAWK", "KGT0900", "1800");
insertdata("3","CERVELOT", "BLUE", "MOD", "DFV3992", "1500");
insertdata("4","HUMMER", "SILVER", "HUME", "AAA6674", "2500");
insertdata("5","MINICOOPER", "WHITE", "COOPER", "CCC001", "1500");
insertdata("6","TATA", "GREEN", "SUMO", "ADW9349", "2100");
char crow[100];
sprintf( crow, "%d", row );
s = s + Table(crow,"5", cars, 6, row);
s = s + echo(messagefont(message, color));
s = s + ForLoop("0","10",messagefont(message, color));
s = s + echo("<br>");
s = s + WhileLoop("3",messagefont(message, color));
s = s + echo("<br>");
s = s + DoWhileLoop("3",messagefont(message, color));
s = s + tE();
file_ops<<s;
file_ops.close();
system("cls");
cout<<"FILE CREATED! \n";
system("PAUSE");
return 0;
}