Formatting Dates with PHP

PHP has a really useful date() function for formatting dates from timestamps. When used in conjunction with strtotime() you can do some really quick and easy manipulation and formatting of dates.

Categories PHP

Using strtotime with PHP

The strtotime() function in PHP allows you to convert English text date time strings into UNIX timestamps. It is useful for converting database datetime strings into UNIX timestamps and also creating dates into the future or past based on the current time or relative to a date and time in the future or the past. This post looks at some examples of doing this.

Categories PHP

Using find to locate files modified in the last 24 hours etc

The Unix/Linux shell command "find" is really useful for finding files on your computer. There are also graphical utilities for finding files, but sometimes it is easier to use the command line, or it’s simply not possible, eg if logged in to a remote server using SSH. This post looks at how to use the find utility to locate files based on the modification time eg looking for files that have been modified in the last 24 hours.

Get unique array values with PHP

The PHP function array_unique() allows you to create a new array which contains only the unique values from the original array. This post looks at some examples of using the array_unique function.

Categories PHP

Splitting a large Apache log file with PHP

A little while back I needed to split a large Apache log file (3.5GB) up into smaller pieces and wanted to break it up into several files, with one for each day of the month. I initially tried using "grep" on the command line but this proved to be too slow, and I needed to run it once for each day and month so it was going to take 92 times to run, extracting just one day at a time over the course of three months. I ended up writing a quick little PHP script which was able to split the 3.5GB file into 92 files, one for each day of each month in under 4 minutes.

 

Categories PHP