PHP
Make prototype.js’s toQueryString method php safe
One hurdle I came across today is Prototype’s Hash.toQueryString() method, which turns a hash into a query string [bet you couldn't have guessed that ;-)]. The wall I ran into was how it parses arrays within the hash, it would take something like this [in JSON]:
{"someArray": [1,2,3]}
… and run it through toQueryString(), it returns:
someArray=1&someArray=2&someArray=3
… [...]
Read Full Post | Make a Comment ( None so far )Memcache & MySQL PHP Session Handler
LAST UPDATED MAY 17, 2009
I have recently read Cal Henderson’s book, Building Scalable Web Sites, and was inspired 6 ways from Sunday on just about every approach I take to web development. I highly recommend you purchase this book, and read through it asap… it is a must read [even though it was published back [...]
Simple Image Resize Calculator Function
Here is a simple function to calculate the width and height of an image given the constraints you want the image to fit in. This is great for creating thumbnails which need to fit into a specific height / width.
To call the function, pass in the current height / width of the image you’d like [...]
Using Memcache with MySQL and PHP
Memcache is a great caching tool available for nearly every scripting or programming environment. I use it with PHP to speed up some applications I have written by completely avoiding asking the database for information. I wanted a very clean way of implementing this in my various projects, with as little change to the existing [...]
Read Full Post | Make a Comment ( 30 so far )Use one DB connection on your custom wordpress install
Like most people who use WordPress, I have hacked a few installs 6 ways from Sunday for some of my projects. While digging through my hacks I had noticed that the script was connecting to my database TWICE per client … once for my website it’s self, then once for WordPress’ needs. This seemed like [...]
Read Full Post | Make a Comment ( 2 so far )Make your website completely UTF-8 friendly
LAST UPDATED JUNE 15, 2009
Running an Internationalization / Localization [or i18n / L10n] friendly website can be tricky, and sometimes downright maddening for those who haven’t yet delved into the world of Unicode. Allowing your users to post in whichever language and / or characters of their choice to your site is crucial for any [...]
Never use ORDER BY RAND() again!
I have been guilty of using ORDER BY RAND() in MySQL queries to return random records from time to time, but everyone knows to avoid it like the plague. For those who agree with me, aside from using it on very small tables [1 - 500 records], I have an elegant workaround using PHP.
<?php
[...]
Installing memcache on Windows for PHP
LAST UPDATED MAY 7, 2009
Installing memcache on Windows XP / Vista is kind of like voodoo for those of us who are not disciplined with compiling code from source. I initially attempted to install memcache a few months ago after reading a few articles about how much performance it can pump into your web application. [...]
Matching a word / characters outside of html tags
Today I spent a good 2 hours on this very simple regEx problem. I tried googling just about every set of search terms I could think of, and didn’t find anything useful … basically I wanted to replace a certain word inside a string with another word, but not within html.
To do this I used [...]
Creating Pixelated / Mosaic images with GD in PHP
A simple way to create a pixelated [or mosaic-looking] image in PHP using GD is to, in theory:
Create a image resource for the soon-to-be-pixelated image
Resize the image to 5% of it’s original size [adjust to taste]
Save image to server or send to browser
Using the script below will turn the image on the left into the [...]
Read Full Post | Make a Comment ( None so far )