Archive for the ‘php’ Category

PHP Autoload Classes Recursively

This method will autoload any directory of class files recursively, in under 10 lines of code. This only works with 5.3.1+.

spl_autoload_register(function($class){
$rdi = new RecursiveDirectoryIterator(’/path/to/lib’);
foreach(new RecursiveIteratorIterator($rdi) as $file => $meta) {
if(($class . [...]

CodeIgniter ModRewrite for Dreamhost

Recently I began diving head first into CodeIgniter, a PHP MVC framework. During the installation process I ran into a major problem with URL rewriting within the CodeIgniter environment and Dreamhost.
CodeIgniter provides an .htaccess solution to create friendly URLs. Which in most cases works very well. However, with Dreamhost this solution does not work. The [...]

Order Posts by Meta Value Numbers in Wordpress

The following changes work on Wordpress version 2.8.*, prior version will need a slightly different change.
A brief background first. I needed to have a page in which my posts were ordered by the meta_values to a particular meta_key. By default meta_value is LONGTEXT data in mysql, therefore we are unable to order posts by meta_value [...]

Creating a PHP Verification Image

You will need to have GD library loaded on your server, and you should be using PHP4+. To check to see if you have either of these running, simply create a file, call it whatever you want, I call mine info.php. Place the following code in there:

1
<? phpinfo(); ?>

If all checks out, then you [...]

Optimizing PHP & SQL

Commonly we see php being used as an interface between the client and the database providing the information. Very few implementations utilize optimization, and thus, reduce performance. Listed below are many techniques that should be used to optimize php to sql communication.

Do not use SELECT * unless you must
Use SELECT priorities for better control
SELECT [...]