Search code examples
phpc++cprogramming-languages

Possible to write an HTML form in C or C++


I use PHP and I know that PHP is written in C or uses C somehow. I'm trying to understand lower level languages. So can someone explain to me how the HTML that PHP generates (let's say the markup for a form) is built with C. Can I build a web form in C or C++ and how?


Solution

  • It's possible to write a Common Gateway Interface (aka "CGI") program in any computer language which can send text to the standard output channel (i.e. pretty much every one):

    #include <stdlib.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("Content-type: text/html\n\n");
        printf("<pre>Hello, World!</pre>\n");
        return EXIT_SUCCESS;
    }
    

    [html, body, etc tags omitted for brevity].