Posts in: PHP
- 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 [...]
[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); // second parameter returns [...]
[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 with associative arrays.
If you [...]
[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 views.
Experience with PHP [...]
[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 and [...]
[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.
#Input text [...]
[26 Feb 2008]
- Review: Learning PHP Data Objects by Dennis Popel
- Packt Publishing graciously provided me with a copy of this book to review.
PHP supports more than a dozen database setups, including the SQLite library bundled with PHP 5. That’s a lot of databases, and each one has its own connection syntax and server-specific functions.
So what happens when you want to be able to [...]
[23 Oct 2007]
- Solution for “Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’” error when using PDO
- If you’re trying to get up-and-running with PDO, you may experience a “Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’” error when trying to connect to your database, even if your php.ini and my.cnf files contain a different default socket path for MySQL.
It’s counterintuitive to a degree, but it’s actually expected behavior. The good [...]
[22 Oct 2007]