Sort Multi-Dimensional Array By Value In PHP

The following code snippet will help to sort multi-dimensional arrays by a value of one of the elements. If you look at the code below we have an array populated with 3 other arrays, each of them has...

Get Image Src With PHP

There are some occasions where you need to get the attribute value in PHP from a HTML element, this can be for migration reasons or perhaps you are writing a script to scrap a website to store the val...

File_Exists For Remote URL

If you want to make sure that a file exists in PHP you can use the function file_exists(), which takes one parameter of the filename. // Returns true if the file exists file_exists( $filename ); Thi...

Calculate Different Shades Of A Colour

There are different ways colours are defined the two most popular values in web are HEX or RGB. Both of these values have a logical formula to working out what colour each value means, because of this...

Learn How To Use DateTime With PHP

In version 5.2 of PHP the DateTime class was introduced, in this tutorial we are going to investigate how the DateTime class can be used and why it's better to use this class over the old date() and t...

Prefix URL With Protocol In PHP

Here is a useful function I use in many of my applications, it will take a URL and see if it's prefixed with a protocol, if it's not then it will add the default prefix to the start of the string. Thi...

Cache Google Web Fonts Api

Google web fonts is a huge library of free web friendly fonts you can easily use on your website. The fonts are loaded in to your website with Javascript and display by using font-family property in y...

Force Browsers To Load Latest CSS And JS

In modern browsers they will cache most external aspects of the website, they will cache all images and even stylesheets and javascript files of your website. During a website redesign where you can c...

PHP Include All Files In A Folder

If you want to instantiate a class in PHP the class must be loaded into your application before you can use it. There are 4 ways you can load a class into your application include, include_once, requi...

PHP Template Engines

A PHP template engine is a way of outputting PHP in your HTML, without using PHP syntax or PHP tags. It's suppose to be used by having a PHP class that will send your HTML the variables you want to di...

Register Your Own Autoload Functions

PHP has a few in-built magic method __get(), __set(), __sleep(), __toString() etc. These functions are all really useful but they are not used very often in your day-to-day development, but one magic...

Remove Characters At Start And End Of A String In PHP

In a previous article about how you can remove whitesapce from a string I spoke about using the functions ltrim() and rtrim(). These work by passing in a string and they will remove the whitespace. Us...

Store HTML View File In A Variable

If you have used a MVC language before you would be familiar with the practice of separating your business logic from your HTML. The way this works in MVC language is that the framework will allow you...

Hash Passwords With PHP 5.5

Almost every PHP developer would have to build an application that relies on a user login. This will involve the user of the website having a Username and Password which is stored in the database so t...

How To Compare Strings In PHP

During any sort of programming you will always get situations where you need to compare values with each other, if the values are boolean or integers then the comparison is simple. But if you want to...