开发者

First php script - no output [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I work with WAMP server 2.2.17 and PHP 5.3.5. I'm trying to make a PHP script in ConTEXT (text editor). I type literally this:

<? php
"hi everyone";
?>

And save this with Save as... an开发者_开发问答d give the file name: "test.php" (I put " that to be sure that he would not changed my extension to .txt) Save as type: All files (and I try with PHP). I went to WAMP, refresh him and nothing. I type in root location http://localhost:8080/test.php and nothing happens. Does anyone know what I am doing wrong? Or what else I should do?


It is not valid code. try

<?php
echo "hi everyone";
?>


You can look at the source code of a page (press Ctrl+U or right-click in most modern browsers), and you'll see the php code.

This means php did not interpret your code. One reason could be that php just echoes everything not in <?php ... ?>, and can, unlike a human, not recognize your similar <? php (note the space character). Another one could be a misconfiguration of php or Apache, most likely missing (AddType x-httpd-php .php or php's configuration).


You just created a string variable. You will need to send this to the browsers somehow.

In PHP this can be done with echo, which sends output to the users browser.

So for example:

$vartest = 'Hello ';
echo $vartest;
echo "World!";

Would send "Hello World!" to the page when you visit it with your browser.

But this assumes you get a blank screen and not a error screen that complains about not finding the website. If this is the case you should check your server.

Also, PHP code bloack starts with either a <?php or for short <? and ends with a ?>. Your code would be between these two.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜