开发者

PHP Script not working [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JS百科 Closed 10 years ago.
<?php
include("stdio.h");

function main()
{
    printf("Hello World");
    return 0;
}

?>

Error on line 2? Dunno what I'm doing wrong.


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.


It's likely C, not PHP. Try

<?php
    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.


Line 2 is include("stdio.h");. This is unnecessary.


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 correct PHP equivalent of that pseudo-C program is:

Hello World

Note: no <?php opening tags required.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜