<?php
include("stdio.h");
function main()
{
printf("Hello World");
return 0;
}
?>
Error on line 2? Dunno what I'm doing wrong.
<?php
include("stdio.h");
function main()
{
printf("Hello World");
return 0;
}
?>
Error on line 2? Dunno what I'm doing wrong.
PHP isn't C. There is no stdio.h, nor is there printf. (But echo is usually used if not formatting.)
echo "Hello World";
The include() statement includes and evaluates the specified file.
So, PHP will try to parse the contents inside stdio.h and since this is likely full of C Code, there will be errors, because that is not what PHP expects to find in there.
Check the PHP Manual for further reference.
As others have said, your code looks like C code inside a PHP tag. Here is the PHP equivalent of what you're trying to do:
<?php
printf("Hello World");
?>
However, if you actually did need the main() function, it would look like this:
<?php
function main()
{
printf("Hello World");
return 0;
}
$returnValue = main();
?>
This would have the result of echoing the string "Hello World" and setting $returnValue to 0.