Learning PHP The Right Way From The Start

Web Design & Marketing Blog


Learning PHP The Right Way From The Start

Starting to make websites is easy, powerful, and scalable with PHP. PHP was designed from the ground up to be easy, and has since evolved into a fully object-oriented language that has been successfully used in many large scale web applications. PHP is wonderfully flexible, and can easily be added to any JavaScript or HTML just by putting PHP code between the tages “<?php ” and “?>”. Some critics accuse PHP's lenient code of being a reason to not use the language, but I strongly disagree. Still, it's important to learn PHP the right way from the start.

Get PHP

The first thing you need to do is get PHP. The easiest solution for a beginner is to get XAMPP which has a version for all major operating systems, and easily installs everything you need to start writing PHP. Then you just run the XAMPP control panel and click the start button next to the words Apache and MySQL. Then you can make files with with the .php extension in the folder called htdocs where you installed XAMPP, and see them run in your web browser by typing “localhost/” followed by the name of your file.

The only way to learn how to do it is to try it. So if you don't have it installed already, do so now. Once you have started Apache, find the folder called htdocs which will probably be located somewhere like C:\xampp\htdocs on Windows. Then, open up Notepad

or something, but not a word processor, and write:

<?php
echo “Hi”;
?>

Save the file as “hello.php” in the htdocs folder and type “localhost/hello.php” in the address bar of your web browser. You should see nothing but the word “Hi.” Simple? If you don't think so, try running your first C++ program. PHP is as easy as it gets.

Get A Program To Write PHP In

The next step is to get a program to write your PHP in. Never use a program like Microsoft Word to write computer code in. Word processors add invisible stuff to files that programming languages won't know how to handle. I've tried many programs for writing PHP, but for a beginner I would not recommend anything but Notedpad ++.

Never Make .html Files & Never Rewrite Anything

Every HTML file you write should be a .php file. If your website has to use the same header, footer, or menu on more than one page, you need to put it all in one file and write “<?php include('/headerFolder/header.php'); ?>” wherever it is used. The most basic HTML pages need at least that much server side scripting to be half respectable. If you ever catch yourself copying and pasting the exact same code into another place on your website, then you need to put it in a single place and use PHP to get it. Never rewrite code.

Get A Framework

I would strongly recommend using a framework or content management system. This is where a lot of people start off in the wrong direction, and so I urge you to bother with it. These things are what make web sites like VivaNet 2.0's Lexy Sites stable, fast, and flexible. If you're getting lost and you need a website now, you may want to get hosting with us and get a website set up for free with it.

A good content management system, or CMS, for a beginner is WordPress. A good framework for a beginner is CakePHP. Other great options include Zend and Joomla!. The difference between a framework and a CMS is mostly that a CMS has a built in admin section to add content. There's more to it than that, but that's the difference you're going to be concerned with at the very beginning.

It's so important to learn a framework when you learn PHP. You aren't going to be able to go into the job market with PHP on your resume without knowing more than how to use it to put your HTML header on every page in your site. I would recommend that you choose one framework, and stick with it as best as you can until you've gotten enough of a hang of things to learn more.

Play Around

The next step is to use PHP. Check out a tutorial like W3 Schools. If you ever need to look anything up, you can read the manual at php.net. Whatever experience you've had with manuals in the past, forget it when it comes to the php.net manual. It's easy to read and each page allows forum posts for the thousands of people willing to help beginners. A great place to ask questions or look up your questions if you're scared of the manual or if you can't find answers in it is Stack Overflow.

And don't be shy to mess around in your framework's back end code. The best things I've learned from PHP I learned from messing around with other people's code. That's one of the many reasons I urge you to begin writing PHP in a framework or CMS. You can figure out how tried and tested methods work, and how you can change them to do what you want, and it's amazingly fun.

One of the many great things about PHP is that it's easy and quick to get started with. You don't have to take the time to learn a lot of the techniques for stable web sites in order to get amazing results. Just getting used to PHP and a new framework or CMS is enough to swallow in one sitting, but once you feel comfortable with these new toys there are a lot of best practices you should learn.

You can find part two of this series: Learning PHP the Right Way From the Start Part 2 - Best Practices

OUR LATEST TWEETS

Testimonials

VivaNet2.0 constructed website, myUSAi.org according to our exact technical specifications and with our required timeframe and budget. We liked VivaNet2.0...

Steve Wilson, myUSAi.org

GET SOCIAL
  • Facebook
  • Twitter
  • Linkedin
  • Feed