Jul 16

PHP function to generate n-grams

Here’s a code snippet fresh from my PHP n-gram search class. The $str arguement
expects a string, $size is the length of the desired n-gram, and $clean lets us
opt-out of some “clean-up” where duplicate n-grams are removed, and non-alphanumeric
characters are removed from the string. It both returns an array and sets a class value.


Jul 11

Freebie Friday: Dumping values with nice formatting on the web

Here’s a freebie since its friday. Print_r is a great debugging function, but it
doesn’t format well in a web browser. I’m sure 99.999% of php coders have this already,
but if not you’ll slap yourself in the forehead for not thinking of it sooner (I know
I did, you have no idea how long I [...]


Jul 11

Easy way to optimize all tables in mySQL with PHP

I ran across a pretty old “hack” that grabs a list of all the tables and forces
them to optimize. Its generally a pretty useful script to schedule and run once
a week. For those of you playing the home game, you’ll need to tap into your own
database class or adjust it to use the [...]


Jul 6

PHP: Single Quote vs. Double Quote Optimization Notes

Optimizing PHP with the by using quotes properly in echo statements is a pretty easy
thing to do, and it will also enhance the security of your script ever-so-slightly.


Jun 30

Using RegEx to remove crazy characters

Here’s a useful (and easy) regular expression.

Problem: Internally, people continue to cut and paste from dozens of different and
very unique programs. This often includes special and non-printable characters
that break either web presentation or xml feeds.


Jun 27

PHP Singleton

Here’s a code snippet for turning classes into “Singleton” objects. Basically,
this is for when you have a class and you don’t want to create a bunch of instances
of that class.