Hi ,
I am in need of code to compile a C program using PHP in Linux Server...
Plz Help me... Thanks in Advance

Regards
Scorpion

    You can't. C and PHP are not the same languages. You compile C programs using C compiler (in linux g++ for example). Above all you can't compile php scripts using php as well, as scripts are "compiled" at run time.

      The most you could do from inside a PHP script is to [man]exec[/man]ute the compiler available to you, assuming you have permission to do so.

        I think u people cant get the thing quiet right...

        Think that we have a web page which accepts C code from user and displays the compiled and executed result to user in that web page. By the by we want to compile the C Code in server and send the errors or result to the client(browser). Like www.w3schools.com - example section...

        Thanks in advance
        Scorpion

          Are you talking about how they give you the "Source" and then the "Result" right next to it? All they are doing there is printing the source to the screen and then typing the output. They're not actually compiling and using the compiled script to output the "Result". They do basically this:

          This code would go in the little Source DIV box:

          <?php
               echo "Hello World!";
          ?>
          

          And this would be actually manually typed into the Result DIV box:

          Hello World!
          

          They're not actually compiling, they're manually showing you the source and then manually giving you the product of the source when compiled at runtime.

            Hi rsmith,
            Ya You r correct but i need the real compilation on server for a source program given by user and result to user which generated by the compiler in server

            Thanks
            Scorpion

              Then as bgrafelman suggested, your only option would be to use exec to call the compiler you have available on your system. As for printing it back to the screen, your guess is as good as any of ours since you can't use PHP to display compiled C code.

                Write a Reply...