JavaScript has a native method for executing a function periodically: setInterval. But in PHP, it’s a little bit harder. PHP lacks a setInterval equivalent. The closest we can get are the sleep(), usleep(), and time_nanosleep() functions. These functions delay script execution by a certain period of time (either seconds, microseconds, or a combination or seconds [...]
[25 Oct 2011]
One of the neat things about HTML5 is that it allows for multiple file uploads in one file upload field. Of course, you have to have a browser that supports such a feature. Currently Opera 11.10 does. So do Firefox 4, the latest version of Chrome, and Safari 5.0.4. (Internet Explorer 9 does not.) Now [...]
[29 Mar 2011]
Two years ago, I posted about CodeIgniter‘s “Disallowed Key Characters” error message, and one possible cause. Recently, I stumbled across another cause: disallowed characters in a POST array. In my case, I had single-quotes as part of the variable name. My fingers mixed up PHP array syntax and HTML form syntax. <!– will cause the [...]
[21 Jul 2010]
Try Donovan Schonknecht’s Amazon S3 PHP Class because it supports large uploads and doesn’t require PEAR. Set your Content-Disposition request header to ‘inline’ if you want files to display in your browser rather than forcing a download Use S3::inputFile() when copying data from a source file — when uploading, for example. You don’t need to [...]
[12 Apr 2010]
PHP Classes interviews Khaled Al-Shamaa about his AR-PHP project, a series of PHP classes designed to handle Arabic-language web applications. Because Arabic uses a non-Latin character set, it presents a new set of challenges. PC: Developing Web applications in Arabic requires special care. What are the most important concerns and what components do you provide [...]
[18 Nov 2009]
An alternative to subst() that selects entire words rather than a specified number of characters. I used this on a recent project where I needed to create a meta tag description from text and HTML stored in a database. Uses PHP’s native str_word_count() function. function select_number_of_words($input,$number_of_words){ $output = ”; $input = strip_tags($input); $input = str_word_count($input,1); [...]
[26 Mar 2009]
Or, you know, just use the shuffle() function. Kim points out the drawbacks of shuffle in the comments below. A custom PHP function. This function will return an array that’s been resorted in a random order. Supports both numerically-indexed and associative arrays. Uses PHP’s native array_rand() function. function array_randsort($array,$preserve_keys=false){ /*————————————-/ Preserving the keys works best [...]
[11 Mar 2009]
Google Analytics allows you to collect pretty robust data about how users move through your e-commerce site. Here’s how to make it work with Zen Cart, an open source shopping cart. For this tutorial, you will need: A Zen Cart-based shopping cart A Google Analytics account and the tracking code for both conversions and page [...]
[19 Feb 2009]
While working on a recent project, I had to build a feature that displayed a list of files available in a directory. A simple way is just to use scandir() and a foreach loop to spit out a pretty list. There’s a small problem though: long lists aren’t all that user friendly. I decided instead [...]
[14 Dec 2008]
Marco Tabini & Associates, publishers of PHP Architect and Python Magazine are bringing their php|works conference back to Atlanta this fall, November 12th through 14th, 2008. This year, though, the conference has an added bonus: PyWorks, a conference devoted to Python. Registering for one conference allows you to attend both. Both conferences have an open [...]
[18 Jul 2008]