There appears to be a problem with PHP5 when performing a forced download of a WORD file having the extension .doc or .docx from a web page. Adding ob_clean() and flush() prior to reading the file seems to have resolved this problem. Add the following lines before reading the file from disk.

 … Read More

The way to execute PHP on a .html page is to modify your .htaccess file. This file may be hidden, so depending upon your FTP program you may have to modify some settings to see it. Then you just need to add this line for .html:

Or for .htm

If you only plan… Read More

This has to be one of my favorite time savers. If you’re an experienced PHP programmer you separate your common methods (aka: functions) into Class files.  Over time, this can become an organizational nightmare if your application became large. There is an easy fix for this using PHP’s spl_autoload_register.  This not so well known function… Read More

When you put UTF-8 encoded strings into an XML document you should remember that not all UTF-8 characters are accepted in an XML document You should strip away the invalid characters, else you’ll have an XML fatal parsing error tossed during parsing. It’s rather easy to accomplish this using the following function.

 … Read More

The architecture for an application I created for a client required a method to auto-load a set of widgets (aka: individual PHP scripts) located in the “widgets” directory on the server.  This solution worked perfectly.

Of course, you can enhance this script by refactoring it into a function and adding additional filters to allow… Read More

Recently I needed to take a list of URL’s from a database and present them in an HTML table.  I needed to split the list into an equal number of list items per column in the table. The PHP script function below accepts a single array of items which could be URL’s, words, phrases, or… Read More

These days taking advantage of Search Engine Optimization (SEO) by packing the URL with a string of words is commonplace but not all strings are safe to use in a URL.  The following PHP script function will prepare your string for use in a URL.

 … Read More

When you have the need to do a little house cleaning on your storage system programmatically you can use PHP’s glob() and array_map() functions to make easy work of this. In this example, we are going to find all text files in “some/dir/” and unlink (aka: delete) them. The PHP glob() function gets us our list of… Read More

The PHP glob() function returns an array of filenames or directories matching a specified pattern. This function returns an array of files or directories or FALSE on failure. Syntax:  glob(pattern,flags) Example:

The output of the code above could be:

 … Read More