I am not a demanding man. I have a directory of images; I want a list of the images inside. The usual drill is to create a directory handle and loop through, returning everything that’s found, then close the handle, like so: <?php $dir = “/var/www/vhosts/example.com/images/”; $handle = opendir($dir); while (false !== ($file = readdir($handle))) […]
Here’s a very handy little snippet for stripping all non-alphanumeric characters from a string: $string = preg_replace(“/[^A-Za-z0-9]/”, “”, $string); This will leave all letters (whether they are capitalized or lowercase) as well as numbers 0 through 9.
Qualifying a query in CakePHP is as simple as adding conditions to the conveniently-named “conditions” array, like so: // return array of all musicians $all = $this->Musician->find(‘all’); // return array of all available reed players $only_available_reeds = $this->Musician->find(‘all’, array( ‘conditions’ => array( ‘category’ => ‘reeds’, ‘status’ => ‘available’ ) )); If the array contains multiple […]
WordPress is, for the most part, pretty intuitive. However, one place where WordPress complicates things unnecessarily is in finding the current theme directory. That’s not to say there aren’t intuitive ways of obtaining this information already built into WordPress: Need the current theme URL? Use get_template_directory_uri(). Need the absolute path to the current theme directory? […]