qq_tracker_code_advanced_default

PHP Basics : Introduction To PHP

0


Before we doing any coding, let’s talk about what PHP is. PHP (Hypertext Preprocessor) is a widely used scripting language that is designed for web development and can be embedded directly into HTML.

What makes PHP so different from client-side languages like Javascript and HTML is that PHP code is executed on the server, and then sent to the client as HTML. The amount of things that PHP can do versus HTML and with HTML, make the possibilities of what a web page can do grow exponentially.

One of the strongest features of PHP is its ability to connect to a wide range of databases. Those features will be touched on in later, more advanced tutorials.

This tutorial and any further PHP tutorials will assume that you will be using a server that supports PHP, and that you know HTML. If you don’t know HTML then I strongly recommend not reading this tutorial until you’ve learned it.

Now let’s begin writing your first PHP script.

  • Note – There are several programs you can use for writing PHP, but if you don’t have a specific program such as Adobe Dreamweaver or Panic Coda, you can simply use your computer’s most basic text editor.

First off, create a new file and save it as helloworld.php. Yes the infamous ‘Hello World’. If you don’t know what I’m talking about and plan on learning other programming languages later, then get used to seeing ‘Hello World’ as your first tutorial.

I’ll start by showing you the code, then explaining it piece by piece after you’ve looked through it. I’ve found that’s the best way to work with stuff like this.

Yup, that’s it.

We start by creating a blank html document with all of the standard tags. Only one thing, there’s something new in the body tag.

Whenever you write PHP code, you have to start with “<?php” and end it with “?>”. This lets the server know where the PHP code is within the HTML file.

  • Note – “<?php” tags can be placed anywhere in the HTML document.

The only line within the PHP tag is “echo ‘Hello World’;”. The ‘echo’ command tells PHP to write on the screen whatever text you put within the following quotes.

  • Note – You can use either single quotes or double quotes for ‘echo’, but whichever one you open with, you must close with as well.
  • Note – You can also put HTML code within the quotes following ‘echo’. This will become very helpful later.

The last thing in the line is the semi-colon, which has to be placed at the end of every PHP line, to let PHP know that the command is done, and to move on to the next line. Without the semi-colon, the page would result in an error.

Here’s what your page should look like after opening it in your browser :

First PHP page.

That’s really all there is too it. Thanks for taking the time to read this tutorial and I hope you enjoyed writing your very first PHP script. If you have any questions, please comment below.

Similar Posts:

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Be Sociable, Share!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!