Before we start learning PHP we should at least get a basic idea of what that is. So here it is:
PHP is a server-side scripting language originally created for building interactive and dynamic websites. The syntax of PHP is quite similar to C and Pascal.
Not much, heh? Well, I’m not a history teacher, so we’ll skip that stuff. You can read it yourself when you have a good catch on PHP.
In our day and age there are tons of websites and elearning tools out there that allow you to become a pro in a particular realm before you know it. It goes without saying that you need to work your socks off to make that happen, but it’s totally doable and PHP is no exception.
Why do I need it?
So what is a “dynamic” website? It basically means that the content of a web page can automatically change each time it’s viewed, or the page can respond to user’s input. If we compare it with a static website – HTML web page – its content always stays the same, until it’s been edited. A good example of a dynamic website – blogs and forums, where you can leave a message, and all the other site visitors will be able to see that.
PHP can help you improve your website in a number of ways. Here’s a great example of what you can achieve with it:
Say you have a site with 10 pages, each page is a separate HTML file. Every page has a top menu with 10 buttons that allow you to switch between the pages. Now what happens, if you want to change a title for one menu button? You must edit that title in each and every HTML file. And that is editing 10 files. Just to change one word! What if there are 20 or more pages? Not the best pastime, is it?
Using PHP you create a separate header.php file with HTML code for the top menu in it. Then using the PHP’s include() function, embed the header.php file into every HTML page. Now when you edit some menu title in the .php file, you then just save and voila. All the HTML pages will display the updated top menu with a new title.
This is just a small piece of PHP’s functionality. Want to learn more tricks to improve your website?
Why use PHP?
Here are some main reasons why you might prefer learning PHP to other languages:
- PHP is one of the easiest programming languages
- you won’t have any problems finding a server to host your PHP based website. 90% of servers are running Apache + PHP + MySQL
- it’s cross-platform – meaning you can run PHP programs on Windows, Linux or Mac and some other operating systems
- it’s free and open-source. A lot of CMSs (content management system) are built using PHP and MySQL. You’ve probably heard and maybe even worked with WordPress, Joomla, Magento or some other CMSs. All those are great examples of the power and flexibility of PHP
This list is not full and I could go on and on. Of course PHP is not perfect and has its own disadvantages, but for a starting web-developer this is the best choice.
What do I need to have?
Unrestrained desire to learn PHP 🙂 That’s the first “must-have” in our list.
Knowledge:
If you have some HTML/CSS experience – that’s great. Don’t worry if not, we’ll concentrate mostly on learning PHP, the layout of the site won’t be our main concern. I will also provide code examples and files to download, so you won’t get stuck at some point.
Server:
As it was mentioned above, PHP is a server-side scripting language. So we need to have a server with PHP installed. You can use your server (if you have one), but it’s better to develop and test a PHP application locally – cause uploading files back and forth just to make a small update may become quite annoying.
So we’ll stick with the second option – local server. It’s quite easy to install and configure. Before you proceed with the rest of the article check this post on how to install and configure local WAMP server. When the server is up and running we’ll continue on.
Software:
Basically we do not need anything. A PHP file can be opened/edited using any text editor, like Notepad for Windows and TextEdit for Mac. Or you could use something “huge” and expensive like Adobe DreamWeaver.
But… personally I would recommend Notepad++. It’s absolutely free, light-weight, fast and has a great syntax highlighter. This is the only piece of software we’ll need. At least to get the ball rolling.
Conclusion:
So let’s see what we have learned so far 😉
- learning PHP is easy, as you don’t need any experience with other programming languages or specific software
- it’s flexible, powerful and constantly improving language
- it’s widely-spread over the web. You’ll easily find a server for your website and even move from one server to another
Ok, enough of the theory let’s get to practice. Learning PHP for absolute beginners – Your first PHP script