• Welcome to ForumKorner!
    Join today and become a part of the community.

Hello World - PHP Tutorial

Factor8™

Active Member
Reputation
0
I've noticed that we don't have many PHP tutorials. Here's a basic one on how to print "Hello world!" to the users' screens.

There are many different ways to output data. The most common is to use the echo function, demonstrated below.

PHP:
<?php
echo "Hello world!";
?>

Let's break down this code.

PHP:
<?php

This is the tag that all PHP scripts need in order to "activate" PHP.

PHP:
echo "Hello world!";

This line makes use of the echo function. It's pretty self-explanatory. This function outputs what ever is in the quotes. You can also use two apostrophes instead of quotes, but try to be consistent. And never forget that most of time, your lines should end with a semicolon!

PHP:
?>

Simply signifies the end of a PHP script.

The next data output function we're going to use is print(). The print function is demonstrated below.

PHP:
<?php
print("Hello world!");
?>

Same concept applies to this script. You have your opening tags, then the function, with whatever text INSIDE the quotes, your semicolon, and your ending tags.



Hope you enjoyed! More PHP tutorials to come!
 

OliverE

Power member.
Reputation
0
Thanks for this tutorial.
Could you explain the differences between print and echo please.
 

Factor8™

Active Member
Reputation
0
I'll try.


Echo is faster than print, but other than that, there's not much of a difference, and it doesn't really matter which one you use.
 

OliverE

Power member.
Reputation
0
Oh cool, so really most of the time it's appropriate to use echo. Interesting. One less key to type.
I'll have to do some research to see why it's still used.
 

Factor8™

Active Member
Reputation
0
Right, plus, echo has one less letter than print.


I forgot to add that print can also be used like this:

PHP:
print "Hello world!";

And respectively, echo can be used like this:

PHP:
echo("Hello world!");
 

SGT.Code

Active Member
Reputation
0
Nice tutoriel factor very clean and easy to follow
 
Top