PHP Bootcamp: Part 1 – The Basics
*Note: It’s suggested to review over HTML coding guides first before going over PHP.
So you think you’re ready to go beyond WordPress plugins and basic HTML/CSS coding? That’s great! This will add a whole new level to website customization, possibilities and control over fixing any issues that may crop up with your website. It’s also nice to not be at the mercy of other developers, so here are some core fundamentals for coding on one of the most popular coding languages; PHP.
What is PHP?
PHP, or “Personal Home Page”, is an open source scripting language and is compatible with both Linux and Microsoft servers. I recommend using the Atom platform for the coding itself, but using Notepad will work too.
In order for a web page to pull up as a viewable page, there needs a server to execute its code. If needed, you can install WampServer (for Windows) from WampServer in order to use it on your local machine, or if using a Mac you can use MAMP. Alternatively, you can use a web hosting provider to execute your PHP code. Check out some of our shared server hosting packages here. This is possible because the PHP code pulls from the server itself and presents it to the end user, just like HTML. If you’re new to website development, or coding in general, it’s a great continuation point in case you find HTML too easy or you’ve advanced beyond it.
Code syntax and layout
PHP is just like HTML in that the code is normal text. It’s actually incorporated within a website’s HTML text, and a PHP file called firstphpproject.php, for example, would include the code. Here is a practical example of what PHP code looks like:
This will interpret the PHP code that says “Look at me, I’m a php wizard now!” and present it on the screen. It’s best to think of it as a continuation of learning HTML. The “echo” statement has many uses within the language, but for now just think of it as a means to output your information to your screen. This example is shows the basic PHP tag:
Whenever you code in PHP it can be placed anywhere in your structure, but needs to be made within a starting and ending parameter. A good example is commenting out code needs to be done inside parameters, as shown below:
You can comment out with different syntaxes – as shown above – and also within code sentences:
Another cool thing about PHP coding is in regards to case sensitivity. Keywords (e.g. if, else, while, echo, etc.), classes, functions and user-defined functions aren’t affected by various cases, but we will go on to explain many of these concepts further on in our PHP series. Here is an example of echo being tested with this concept:
Keep in mind that this can’t be applied to variable names since variable names are tailored to one specific variable. In the example below, we can see that we made up two variables, both being x and y. We named both of these respectively 50% and 100%, so they will only output the predetermined details onto the screen:
Hopefully with these tips you should be able to have a rooted concept of how PHP works. Next time, I’ll go over variables in more detail, as variables can be used for many useful purposes when displaying text and executing functions for a web page.