Posts in: PHP
- CodeIgniter’s “Disallowed Key Characters” error revisited
- 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]
- Quick tips for working with Amazon S3 and PHP
- 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 in Arabic: An interview with Khaled Al-Shamaa
- 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]
- [PHP quickie] Select a certain number of words from a string
- 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]
- PHP: Sorting arrays randomly with
array_randsort()
- 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]
- Collecting e-commerce conversion data with Zen Cart and Google Analytics
- 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]
- Simple pagination for arrays with PHP 5
- 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]
- Atlanta, GA: php|works and PyWorks
- 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]
- Debugging tip: “Disallowed Key Character” error in CodeIgniter
- After 6 hours of massive anxiety, stress, near tears, one pound on my desk, and some hair pulling, I tracked down the source of a nagging Disallowed Key Character error that I received while using CodeIgniter: an extra line break. The line feed (LF) and carriage return (CR) characters (and their hex code equivalents (%0D [...]
[6 May 2008]
- Turn text files into pull down menus
- UPDATE: This could also be done with the foreach() construct, but here — on my set-up at least — the for loop is a teensy bit faster. I developed this PHP function for a project I’m working on. I’m posting it here in case I need it again, or in case you find it handy. [...]
[26 Feb 2008]