I develop a lot of data parsers and continuously run into composite mailing addresses that require to be split into their meta collections. The following Regex pattern will reformat these two style addresses into XML tag elements. SAMPLE ADDRESS DATA: 1200 Ocean Rd., Narragansett, RI 02882 1200 Ocean Rd., Narragansett, RI 02882-1234 FIND PATTERN USING… Read More

First, note that it is not possible to detect whether text belongs to a specific undesired encoding. You can only check whether a string is valid in a given encoding. You can make use of the UTF-8 validity check that is available in preg_match since PHP 4.3.5. It will return false (with no additional information) if… Read More

Having worked with CodeIgnighter for many years, I’ve crafted the following the following HTACCESS script to meet most CI needs.

 … Read More

In general, there are 2 solutions to this problem: 1. Use $_SERVER[“DOCUMENT_ROOT”] – We can use this variable to make all our includes relative to the server root directory, instead of the current working directory(script’s directory). Then we would use something like this for all our includes:

2. Use dirname(__FILE__) – The __FILE__ constant… Read More

Error settings in php.ini tell PHP interpreter what kind of errors should be reported and where those should be reported. You may enable these settings in your development environment and disable few in your production environment since useful information error reports provide can also be sensitive information that outsiders shouldn’t see. display_errors  Default value of… Read More

Here is an easy way to create HTML select menus for Month/Day/Year. Create three arrays containing the range of values for days, months, years.  Then loop over each array generating the required option tags for each select menu.

 … Read More

The quickest method for generating a unique PIN number of 10 characters in length. We are taking the smallest part of micro-time (milliseconds), encrypting it with MD5, then shuffling the string itself. This creates a very random blend of letters and numbers.

 … Read More

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