This is the Codebabes PHP virgin course. Now we’re finally getting to the real shit. PHP is the most popular server-side programming language on the web. It’s what makes CMS systems like Wordpress and Drupal go. Facebook was originally written in PHP, so if you want to be the next bad ass brogrammer, it’s not the worst place to start.
In this course we’ll go over the basics of PHP. We’ll assume you have some kind of server running so that you can run PHP. Unfortunately you can no longer just use your browser to look at HTML. If you did that with PHP nothing would happen, because the server needs to process the PHP.
To run a server to process PHP on your computer you can use two easy to set up programs, either WAMP for windows or MAMP for Mac. These programs will set up everything you need to develop dynamic sites right on your computer, Apache, PHP, and mySQL.
You’re going to need a basic understanding of HTML, a computer, access to a web server, a browser and your brain. Your brain, a lot, so keep that blood flow headed the right direction.. (wink wink)
PHP is a server side language that allows you to create dynamic pages that interact with databases, and forms. So what does server side mean? Well, when you go to a website, your computer is the client, it is requesting a web page from a server somewhere. Usually this is just a server in a giant building somewhere, but some marketing MBA douche coined these server farms the ‘cloud’. A static page would just get served up, but if it’s a PHP script, the server executes the code on that page.
Let’s start with the hello world program for PHP, and we’ll also see some PHP syntax. Go to your web directory. In our case it’s in the Sites directory. This is where the webserver on our computer is watching. Anything within this folder will be interpreted by the webserver if it gets opened. Lets create the file, ‘helloworld.php’ in our ‘site’ directory. Now write the PHP, like so:
When the web server parses this file it will print out the line “Hello world”.
And we’re programming, bitches.
Print is what’s called a function. Functions perform a predefined action for you.
You can also add HTML markup to the print statement. Let’s add some h1’s around hello world and create an html element like so:
Now look at the web page. You’ll see that only the html code appears. You’ll never see the PHP because it is parsed on the server side, behind the scenes. Awesome work, lets move on and turn things up a notch.