Introduction
We write a simple program to show how PHP works and to see a message on the screen.
We write a simple program to show how PHP works and to see a message on the screen.
<?php echo "Hello World!"; ?>
PHP code starts with <?php and ends with ?>.
The echo command shows text on the screen.
<?php echo "Hello World!"; ?>
<?php echo 'Hello World!'; ?>
// and are ignored by PHP.<?php // This is a comment echo "Hello World!"; ?>
This program shows the message Hello World! on the screen when run.
<?php // This program prints Hello World! echo "Hello World!"; ?>
Make sure your file is saved with a .php extension.
Run the program on a web server or using the PHP command line to see the output.
PHP programs start with <?php and end with ?>.
The echo command prints text to the screen.
"Hello World!" is the classic first message to learn any programming language.
echo statement do in a PHP program?echoecho statement is used in PHP to display text or output on the screen.<?php and ?>, not echo. Variables are declared differently.<?php to tell the server to process PHP code.<php> and <?> are invalid tags. <script> is for JavaScript, not PHP.<?php echo "Hello World!"; ?>
echo command prints the string inside quotes to the screen exactly as it is.<?php echo "Hello World!" ?>
<?php echo "Hello World!"; echo "Welcome to PHP."; ?>correctly uses two echo statements with semicolons.
<?php echo "Hello World!\nWelcome to PHP."; ?>uses \n inside double quotes but PHP does not automatically print new lines in HTML output.
<?php print "Hello World!" print "Welcome to PHP."; ?>misses semicolon between print statements.
<?php echo "Hello World!" echo "Welcome to PHP."; ?>misses semicolon after first echo.
Pass the test and this pattern moves unknown