One line random value from PHP array literal

When you just want to echo one of three things in throwaway code, here’s a simple trick using PHP 5.4’s dereferencing that does it in one line.

Continue reading →

PHP command line plaintext table

Outputting tables on the command line is fiddlier than it sounds, requiring some string padding trickery. Here’s a quick-and-dirty function to insta-win!

Continue reading →

PHP Nano-Router

Custom routers were all-the-rage a few months ago but I’m afraid I missed the boat, so here’s my so-small-it’s-not-really-a-router router.

Continue reading →

6 Vagrant provisioning wins

Six solid provisioning snippets that serve me well and make developing and provisioning with Vagrant a little bit easier.

Continue reading →

Posting arrays and finding names

Google will tell you how to post arrays, but what if you need to determine the name of the variable that was posted?

Continue reading →

Trigger 404 page in WordPress

Sometimes you need to throw a 404 if certain conditions are met and doing so in WordPress requires a little trickery to achieve the full effect.

Continue reading →

Reconciling WordPress & MVC

WordPress might not use the MVC pattern but following it in your plugins is easy with just a minor change in perspective.

Continue reading →

PSR-3 log level descriptions

A quick reference for what each log level should be used for.

Continue reading →

Get a substring between two strings in PHP

So you need to get a substring between two strings? A quick Google returns about 101,000 results, the first three of which are from StackOverflow and solve the problem for rather specific use-cases. I wanted to solve the problem once-and-for-all in a more general-purpose way.

Continue reading →

Converting Objects and Arrays

Unidimensional arrays and objects can be converted by casting (e.g. $array = (array) $object; / $object = (object) $array;) but if multidimensional only the first tier is converted. Here’s the solution!

Continue reading →