Posts tagged php

Join (implode) an Array of String Values with Formatting


In programming, I often need to join values together from an array. Typically this will be to do something on the backend, like join a list of integers together in a comma-delimited string for use in a SQL statement. For those times, the native join/implode functions work fine. Occasionally however, we need to finesse the resulting string to look a little more readable. I wrote a small function to do so. It’s called pretty_join()

Given an array of 0 or more values, pretty_join() will concatenate all of the values together using a common delimiter (a comma by default) except for the last two values which will be joined by the final separator (an ampersand by default).


Find the longest common substring using PHP


I recently found a need to find the longest common substring in an array of strings in PHP. A couple of Google searches didn’t return any relevant solutions, so I decided to roll my own. I haven’t benchmarked this yet for large strings and/or arrays, but it does what I needed it to for my own purpose.


Fascinating argument on the PHP mailing list


This thread from the PHP-DEV mailing list is a bit old now (Nov 2005), but fascinating none the less. When PHP 5.1 was released, an under-tested new “date” object was introduced late in the release candidate cycle. For those of you not familiar with software development, the release candidate cycle is typically where software development is halted and only bug fixes are committed to the source code before a final release. In this case, an entirely new feature was added in the final release candidate with little notice. Not only that, but the new date object itself had only limited functionality and was intended only as a place holder. This probably wouldn’t have been a problem if the new object had a unique name (or if PHP 5 supported object namespaces), but it used the rather generic name of “date”, meaning that any code that any other developer had written previously that relied on a custom “date” object (in fact the popular PEAR library of PHP code includes it’s own “date” object) would break. And since this was done so late in the release candidate cycle, developers had little or no notice that this was happening. All of this is pinned on one developer who is accused of being arrogant several times (and indeed seems so after reading through his responses).

The thread goes on for quite a while (280 posts to be exact); I’m not even at the end yet and I’ve been reading for well over 20 minutes now. Even Rasmus Lerdorf, the creator of PHP, weighs in a few times. It’s really a fascinating read at the behind-the-scenes happenings of an open-source project.

* This post was originally published on November 21, 2006 at

Simple Optimization for PHP and MySQL


From a post at

Here is a list of a few very simple tips for optimizing your php/mysql applications. Keep these in mind while developing.

Read more

* This post was originally published on May 19, 2006 at

PHP style date and time formatting for ASP


I don’t often work in VBScript for ASP anymore as I find PHP to be approximately 100 times more robust. One area where this is immediately apparent is the difference between date formatting options between the two languages. While PHP has its date() function that can format a date in almost any form imaginable, VBScript’s FormatDateTime() is limited to a few constants that I find to be too much or too little information in almost every case where I need it. So to make up for the lack of formatting support I wrote a date()-like function to use in ASP.

It supports about 98% of the formatting options that date does, with anything timezone related being the bulk of what’s missing (since there is NO way to get the servers timezone information via VBScript). Feel free to copy, modify and redistribute as long as you remember to give fair credit. Speaking of which, every bit of this function was hand-written by me except for the Unix timestamp formatting piece which I found at and decided to use because it was right there in front of me.

You can view or download the code as a text file.

* This post was originally published on December 15, 2005 at

Go to Top