Here we have an example for showing simple PHP scripting code which sends the text ‘Hello Word’ to client browser.
Example: Displaying message using ‘echo’ statement.
Here we have an example, how to display a message using ‘echo’ statement with PHP.
Note: Here I am using notepad text editor to write the following code.
Example 1: Display ‘Hello Word’ text.
<html>
<head>
<title>Hello Word</title>
</head>
<body>
<?php
echo "Hello Word";
?>
</body>
</html>
Output:
Example2: Use html tag with ‘echo’ statement.
<html>
<head>
<title>My file</title>
</head>
<body>
<?php
<%-- // here $faname is a variable--%>
$fname = "Arun Singh";
<%--// here </br> is a html tag to break line
// here . (Dot operator) used for concatenate two string--%>
echo "Welcome "." ". $fname." ". "</br>". "in" ;
<%--// here <h5> </h5> is a heading tag --%>
echo "<h5>". "Mindstick". "</h5>";
?>
</body>
</html>
Output:
Example 3: Display numeric value with ‘echo’ statement.
<html>
<head>
<title>My file</title>
</head>
<body>
<?php
<%--// assigned numeric value in variable 'decimal'--%>
$decimal = 105;
echo $decimal ;
?>
</body>
</html>
Output:
Each code line in PHP should have semicolon at the end of line, because semicolon (;) is a separator used to distinguish one line code to another one.
Note: File must have php extension such as .php, .php3 or .php4 etc. Now save this file with ‘helloword.php’ name.
Deploying php file into WAMP Server:
To deploy ‘helloword.php’ file into WAMP server, open the directory where wamp server is installed, and suppose that the installed directory path is ‘C: \wamp\’, open ‘C: \wamp\www\’ directory path and create a folder and put all .php file in it.
Now let’s have snapshot, how to deploy .php file into wamp server.
Step 1: Open ‘C: \wamp\’ directory.
Click on ‘WWW’ directory.
Step 2: Create your own directory to store .php file.
Click on ‘MyFiles’ directory.
Step 3: To open this file on web browser, start wamp server and click on ‘localhost’
Click on ‘My files’ directory.
Click on ‘helloword.php’ file link.
This is your desired result.
Leave Comment