PHP Learn It! PHP Syntax
"Best Deal"

"Bored - Do You Agree?"

Bored - Studied Hard - Enjoy Yourself "TAKE A BREAK"

"Decide Now-So Many Choices"
"Amazing Deals"
Once You Know, You Newegg

PHP Syntax

Welcome! In this section we're going to learn how PHP and HTML works together. We are also going to build our first PHP web page. Exciting! Are you ready?

PHP Tags

Learn PHP and MySQL fast!

Learn how you can start building rich interactive database driven sites like a professional developer easily and quickly...

>> Order your copy now for just $39.95 <<

PHP is a web scripting language which means it was desgined to work with HTML. You can easily embed PHP code into your HTMl code. Hmmm! Nice but how do we do that? Simple. When writting php code, you enclose your PHP code in special php tags. This tells the browser that we're working with PHP. See below.

	//your php code goes here


Now let see how we blend PHP and HTML together.

	<title>my php page</title>
		echo "hello there!";

Echo is a special statement in php for outputing data to the browser. This statement is more often used when we need to print something to the browser. You will learn how to use echo in as we go along.

Note: Note that, at the end of each PHP statement we need need to put a semicolon, i.e. ";" as you see in the above code. Otherwise PHP will report syntax error.

Pretty neat, eh? I remember when i first wrote my php code, i was just so amazed :)
So, let do that. Lets write our first PHP page.

My First PHP Page

  1. Open up notepad.
  2. Copy paste the above PHP and HTML code in notepad.
  3. Now, lets save the file in our www folder, i.e. c:/wamp/www
  4. Remember, we need PHP to run PHP pages on our computer. To install PHP, please go to the PHP installation page.
  5. Name the file my_php_page.php and save it in your www folder.
  6. All PHP files must be saved with extension .php. This is important because we need to tell the browser that we are working with PHP.
  7. Now, go to http://localhost/my_php_page.php in your web browser.

You should see "hello there!" printed out on the browser. Pretty simple, eh?

There you have it. You first web page in PHP. Now, let’s play around with the code. Let’s do some more cool stuff.

Doing Cool Stuff with PHP and HTML

Echo statement is powerful in a sence that you can put HTML code in it and it will render the text as if it was HTML in your browser. Try it!

Example - Make Text Bold

Replace the PHP line in your code to the following code. Save the file and now refresh your page.

	echo "<b>hello there!</b>";

You should see hello there! in bold letters in your browser.

Example - Make Text Green

Replace the PHP line in your code to the following code. Save the file and now refresh your page.

	echo "<font color='green'>hello there!</font>";

You should see hello there! in green in your browser.

Example - What's today's date?

Lets print out today's date using the php date function. Don't worry we will see more examples of the date function in later tutorials. We will learn some useful techniques for printing date in different formats. For now, let's try the following code.

	echo "today is ".date('Y-m-d');

Try it! Replace previous echo line with this line. You should see today's date, "today is 2014-11-28", printed out on your browser.

So, in this section we saw how we can add PHP into our HTML code. This should give you a brief glimpse into how PHP works and what we can do with it. You're now ready to move on to some advance PHP stuff! What are we waiting for, let’s go!

Web Hosting Reviews
Thousands of web hosting USER reviews. Don't sign-up with any web host before checking out the web's biggest web hosting reviews site first, available at

Build large scalable dynamic websites using PHP yourself
Learn PHP like a pro >>

<< PHP Install Top PHP variables >>