PHP for Beginners

Basically, a PHP file is a text file with the extension .php which consists of:

  • Text
  • HTML tags
  • PHP Scripts

To work with PHP you need to know HTML but we are going to generate dynamic web pages with PHP. PHP is not difficult! On the contrary, PHP is often very similar to plain English.

Let's get started with your first PHP page.

Example1: Hello World!

Start by making an simple HTML document, but name the file index.php and save it in the root of the site:

The HTML code should look like this:

<html>
<head>
<title>My first PHP Hello World page</title>
</head>
<body>
</body>
</html>

Now, we need to tell the server when the PHP will start and end. In PHP scripting language you use the tags <?php (start) and ?> (end) to mark the start and end of the PHP codes that the server must execute.

Now try to add the following simple code snippet to your HTML code

<html>
<head>
<title>My first PHP page</title>
</head>
<body>
<?php   
echo "<h1>Hello World!</h1>";
?>
</body>
</html>
	

This will produce following result

Hello World!

But it will be interesting when you look at the HTML code in the browser (by selecting "view source"):

<html>
<head>
<title>My first PHP page</title>
</head>
<body> 
<h1>Hello World!</h1>
</body>
</html>

Example2: Date and Time

Let's make the server write something else. We could, for example, ask it to display the current date and time:

<html>
<head>
<title>My first PHP page</title>
</head>
<body> 
<?php 
echo <h1>Hello World! Date and Time</h1> . date("r");
?> 
</body>
</html>

This will produce following result

Sun, 12 Oct 2014 00:10:02 + 0200

Now the corresponding HTML code looks like:

<html>
<head>
<title>My first PHP page</title>
</head>
<body> 
Sun, 12 Oct 2014 00:10:02 + 0200
</body>
</html>


 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.