PHP: "Hello World"
"Hello world." is the first program most beginning programmers will learn to write in any given language. Here are four examples of the syntax for "Hello world!" in PHP.
Code:
|
<?php $string = "Hello world!"; print $string; // You could also use echo $string; //Or echo 'Hello world!'; // Or, if you are familiar with C, printf can be used too. printf("%s", $string); ?> |
Now, you can see the following output where "Hello World!" is printed 4 times once from each command. Note, that each sentence in php ends with a semi-colon(;). It tells the php interpreter that the command has ended and can be executed.
Output:
Notice that all the code in php is enclosed in <?php and ?>. This makes it easier to separate the php code from HTML when emmeded in it. The following example shows how php can be embbed in HTML to print "Hello World"!.
|
<html> <head> <title> Hello World!</title> </head> <body> <?php echo "Hello World!";?> </body> </html>
|
Output:

Recent comments
1 week 2 hours ago
2 weeks 5 days ago
4 weeks 10 hours ago
4 weeks 2 days ago
4 weeks 4 days ago
4 weeks 5 days ago
29 weeks 1 day ago
29 weeks 5 days ago
29 weeks 5 days ago
30 weeks 18 hours ago