Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo command doesn't do anything

Tags:

php

echo

I've been started studying PHP in my spare time, and the first code example I was given was this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <body>
        <?php
        echo "Hello World";
        ?>
    </body>
</html>

From what I understand, this should write out "Hello World". However, all I see is a blank webpage. Any ideas why this is and how I should go about fixing it?

like image 785
Adam P Avatar asked Jun 20 '10 02:06

Adam P


People also ask

Does the echo command do?

echo command in linux is used to display line of text/string that are passed as an argument . This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file.

Does echo command need quotes?

Although not necessary, it is a good programming practice to enclose the arguments passed to echo in double or single quotes. When using single quotes '' the literal value of each character enclosed within the quotes will be preserved.

What does echo $0 mean?

As explained in this comment on that answer you link to, echo $0 simply shows you the name of the currently running process: $0 is the name of the running process. If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will be the name of the script.

How do I stop the echo command?

The echo command ends with a line break by default. To suppress this, you can set the control character \c at the end of the respective output.


1 Answers

Here's a checklist

  • What server are you running? Does it support php?
  • Is PHP enabled?
  • Is your file named with the extension .php?
  • When you use View Source can you see the code in the php tags? If so PHP is not enabled

As a test try saving this as info.php

<?php
phpinfo();
?>

and see if it displays information about your server

like image 59
Christopher Tarquini Avatar answered Oct 02 '22 15:10

Christopher Tarquini