First PHP Program
First PHP Program
In this tutorial, we will learn how to write the first program of PHP. Before we will start with first PHP program, we need some tools like- PHP, Text-editor or XAMP, WAMP server, and My-sql... etc.
- The PHP script executed on the server and the plain HTML result is sent back to the browser.
- A PHP script always starts with <?php and ends with ?>.
- A PHP script can be placed anywhere in the document with in the php scriptlet i.e. <?php ?>.
- A PHP file normally contains HTML tags, and some PHP scripting code and must have a .php file name extension.
PHP File
- PHP file can contain plain text, HTML tags, internal and external CSS, PHP script and Java-script... etc.
- After PHP files are processed, their output returned to the browser as pure plain HTML.
- PHP filename usually have the file extension of
.php
, .php3
, .phtml
.
- PHP file can contain SQL query too.
How to Write First PHP Program
<!DOCTYPE html>
<html>
<head>
<title>First PHP Program</title>
</head>
<body>
<?php
echo "Hello Tutorials Logic"
?>
</body>
</html>
Save above program as First.php and then open any browser type localhost/First.php in address bar of browser.
Output:- Hello Tutorials Logic
Explation:-
- The <!DOCTYPE html> declaration defines the document type to be HTML.
- The code or text between <html> and </html> describes an HTML document and it will contain almost each and everything of web page or document.
- The <head> and </head> tag can include a title for the document, scripts, styles, meta information... etc.
- The <title> and </title> tag can include a title for the document.
- The <body> and </body> tag can include all the content which are visible on the web page as well as it can contain scripting language code too like- PHP, ASP, JSP, and Java-script.
- A PHP scriptlet i.e. <?php and ?> can include PHP code.
- The main use of echo or print is to show output on the screen.