Shorthand Comparisons In PHP

In this tutorial we're going to investigate how we can improve our code by cleaning up unnecessary code by using shorthand code samples in PHP. So what do I mean by removing unnecessary code? The most...

PHP7 Array Iteration Trick

In this tutorial we're going to look into a look tip for dealing with PHP array iterations with PHP 7. When you're developing in PHP and need to iterate over an array you'll probably see something lik...

Increment Numeric Part Of String

Have you ever needed to increment the number which is part of a string. For example if you have an invoice number with the format und001 and want to be able to automatically create the next invoice nu...

Return Class Constant From Variable

PHP constant values allow you to set a variable on the class which will remain the same and is unchangeable. The difference between these constants and other variables in a class is that they are not...

Getting Started With Composer In PHP

In this tutorial we are going to learn about composer and how we can use it to develop our PHP applications. Composer is a tool that allows to manage your third party dependencies in your PHP applicat...

Sanitize Special Word Characters With PHP

Anybody who has worked with user content on a website will know the problem you get when a user writes the content in Word and copy and pastes this content into a textarea so that you can store it in...

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...

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...

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...

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...

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...