C Programming Tips & Tricks





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Code Snippets
 List All
 Arrays
 Calculators
 Datatypes
 Date & Time
 File Manipulation
 Math Functions
 Multimedia
 Others
 




Create PHP File - C

Snippets  C  Create PHP File
Snippet On
Create PHP File




Code
  
Rate this page :
  [ 0 votes]


#include <stdio.h>
int main()
{
int filehandle;
char filename[20];
char countername[20];
int count;
FILE *fp;
printf(<q>Please enter the name of the file you wish to create\n</q>);
printf(</q>in the format myfile.php : \n</q>);
gets(filename);
printf(<q>Now enter a name for the counter file.\n</q>);
gets(countername);
printf(<q>Please enter the starting count.\n</q>);
scanf(<q>%d</q>,&count);

/*create counterfile with the starting count*/
filehandle = creat(countername,S_IREAD|S_IWRITE);
if(fp = fopen(countername,<q>a</q>))
{
fprintf(fp,<q>%d</q>,count);
fclose(fp);
}
else
printf(<q>cannot open %s </q>,countername);

/*create php file*/
filehandle = creat(filename,S_IREAD|S_IWRITE);
/*create counter in php file*/
if(fp = fopen(filename,<q>w </q>))
{
fprintf(fp,<q><?php\n</q>);
fprintf(fp,<q>$counterFile = \<q>%s\</q>;\n</q>,countername);
fprintf(fp,<q>$line = file($counterFile);\n</q>);
fprintf(fp,<q>$line[0] ;\n</q>);
fprintf(fp,<q>$fp = fopen($counterFile ,\<q>w\</q>);\n</q>);
fprintf(fp,<q>fputs($fp, \<q>$line[0]\</q>);\n</q>);
fprintf(fp,<q>fclose($fp);\n</q>);
fprintf(fp,<q>echo $line[0];\n</q>);
fprintf(fp,<q>?>\n</q>);
fclose(fp);
}
else
printf(<q>cannot create %s</q>,filename);
return 0;
}
}




Other Links

web hosting