Here is a simple PHP code which is used to print/display a string. This program must be stored in the servers root directory as first.php. For the purpose illustrations our example server is http://localhost.
<?php echo 'Now we started to write programs in php'; ?>
This code is used to print a string 'Now we started to write programs in php' in your browser.Here echo is a language construct which is used for one or more string output. For printing strings we can also use print() language construct instead of echo.The main difference between print and echo is that the print() will return an integer value(always 1) and echo will return nothing(void). We can avoid the parentheses while calling echo and print because they are language construct rather than functions.
To run the above program type http://localhost/first.php in the address bar of the browser since we are saving the files inside the root directory.
<?php
echo print('Hello World');
?>
The output of the above program is Hello World1 as the print statement will return 1. Note that we couldnot use print echo statement instead of echo print
The echo statement will have a short form syntax as follows
<?='Hello World'?>
This short form works only if we turn on the short_open_tag of php.ini file. Each of the php statements ends with semicolon but we use short tags it is not needed.