An introduction to Object Orientated Programming in PHP (OOP)

What is OOP? OOP is a method in programming that allows you to encapsulate code into objects. Think of OOP as a bit like the human body. The human body has a lot of moving parts and organs that perform specific tasks such as heart, lungs,

Storing & retrieving data with Arrays

Arrays are like lists. In programming terms arrays are the same as variables that store data but the crucial difference is they store elements of data that is normally related in some way. Think of them a bit like a draw - take a kitchen

Do – While loop: do what why?

Do - while loops are principly designed to reduce code duplication. They enable you to do one thing whilst doing something else. Imagine a coffee shop

How to connect to a MySQL Database using PHP

There are two ways to connect to a MySQL database using PHP. There is the procedural method and the OOP method. Both are valid but arguably the OOP method, using PHP’s Database Object (PDO) is a more robust method in terms of error

Ternary Operator (:?)

The ternary operator is a shorthand for if/else. Why bother with the ternary operator? Wherever possible it makes sense to optimize your code. In so doing you reduce the load on the server and write less code (never a bad thing!). By optimizing your scripts as much

PHP Magic Quotes

What are Magic quotes? Magic Quotes is a function that is designed to help escape potentially Malformed data inputs in PHP forms. The problem with Magic Quotes is that the function escapes not only suspicious characters but inverted commas and speech marks as well.

PHP Sessions

Sessions are designed to exist within a current user session. They also run purely on the server side and unlike Cookies nothing is pushed to the browser’s cache (client side). So, what are sessions good for? Imagine you have a shopping cart site that requires a login

The anatomy of a PHP cookie

What is a cookie? A cookie is a text file that is sent from the server and is stored in the browser’s cache. Cookies can enhance the usability of your application by either setting predefined variables within the application or gathering information entered by the user

PHP Strings

In this post we will explore: Prebuilt string functions Regular Expressions Escaping strings echo vs print printf and sprintf First of all what is a string? Strings are variables, they contain characters (Variable characters). They could also be considered as a type of array. Prebuilt String Functions PHP provides excellent support for strings: http://php.net/manual/en/ref.strings.php.

Global and Local Scope in PHP

Global and Local scope in applications programming is a crucial aspect that needs to be properly understood.  Particularly the global aspect. So what does global mean in a programming context? Global means that data or logic can be accessed anywhere in the application by anything without restriction.