PHP offers two main ways to display information:
1. print statement:
This statement directly outputs text to the browser. Here’s an example:
PHP Code
<?php
print(“Hello, world!”);
?>
This code will display “Hello, world!” on the webpage.
2. echo statement:
Similar to print, the echo statement also outputs text. However, echo can be used multiple times in a single line, while print requires separate statements for each output. Here’s an example:
PHP Code
<?php
echo “Welcome to my website! “;
echo “Today is ” . date(“Y-m-d”) . “.”;
?>
This code will display “Welcome to my website! Today is 2024-05-04.” (assuming today’s date is May 4th, 2024).
Here’s another example of print methods.
Output