HelloWorld in PHP


 

HelloWorld in PHP

Hello World in PHP tutorial has a program which includes all the little necessary things,it includes small description about echo, print etc.

Hello World in PHP tutorial has a program which includes all the little necessary things,it includes small description about echo, print etc.

Hello World in PHP Program

To write and run your first PHP program, open the www folder and inside the folder create a folder with any suitable name (e.g. your name : rose), then create a .txt file and save it with any name and .php extension (e.g. HelloWorld.php) 

Inside the file write:

<?php

echo 'Hello World';

?>

In the above coding  <?php ?> is delimiter of php language, every php coding should be done inside this tag. You can embed this tag inside html coding, but that is optional and completely depends upon the requirement of the project/program.Every line of the coding must end with a semi-colon.

echo is not a function, it is a language construct, you do not need to use parenthesis with it as necessary in some other language constructs If it is required  to  pass more than one parameter, the parameters  needless to send within parenthesis. echo also has a shortcut syntax, where you have to use an equal sign immediately after the opening tag <?= "hello"?> , but it is required to enable the short open tag to use this option. To enable this option click the WAMPSERVER- icon, select php, then php settings and finally you can see the short open tag.

General format of echo is:

void echo (string $a [,string ... ])

echo does not  return any value.

Another way to print any text is print(), it is also a language construct not a function. So you are not required to use parenthesis with the argument list.

General format of print is :

int print(string $arg)

print always returns 1.   

Now again save it and close the file, start the server, click on the localhost link, it will open the home page of the server and then click on the php / rose link, it will display the list of php files, for now you can see HelloWorld.php. Click it and it will display:  Hello World on the screen. 

Ads