PHP email validation
11
Enforce loadig fresh script code for the external javascript files. Compatible with HTTP 1.0.
21
If you've ever wanted to build an application that can both find the distance between two zip codes, and find zip codes within a specific radius of another zip code, then this is the snippet for you.
I've tried to build this before using PHP4 and MySQL 4 and have found it to be painfully slow for a one-user connection over a Local Area Network (LAN). So, before you continue reading, I must make it abundantly clear that this method requires PHP 5 and MySQL 5.
This is because in PHP5, we will need the MySQL-Improved interfaces, and in MySQL 5, we will need functions and procedures.
Using functions and procedures in MySQL puts the weight of the calculations on MySQL, where they will run hundreds of times faster than if PHP were to attempt to do the work. In addition, using functions and procedures is still hundreds of times faster than carefully crafted SQL statements (one benchmark took over 10 seconds using a WHERE clause, while the function + procedure method took around .12 seconds--note the dot).
Since I am not a mathematician by trade, I found the necessary calculations using Google.
For the "Great Circle Distance" formula, I used Meridian Word Data's website. For the radius finder, I used another that unfortunately I do not have off the top of my head right now. I will look for it again and repost it for proper accreditation.
For the zip code database, I am using the free zip code database from CFDynamics.
Below, you will find the database and table schema, the functions and procedures, and also a demo PHP script to see all of this put into action. As a courtesy, you may download a dump of this database from my website. It's uncompressed size is 3.4M, and it's compressed size is 537K. The checksum is available here.
Please leave me comments, suggestions, questions, and/or rants about this snippet. I feel this is a very useful bit of code, and hope that others out there may find as much use from it as I will be.
I've tried to build this before using PHP4 and MySQL 4 and have found it to be painfully slow for a one-user connection over a Local Area Network (LAN). So, before you continue reading, I must make it abundantly clear that this method requires PHP 5 and MySQL 5.
This is because in PHP5, we will need the MySQL-Improved interfaces, and in MySQL 5, we will need functions and procedures.
Using functions and procedures in MySQL puts the weight of the calculations on MySQL, where they will run hundreds of times faster than if PHP were to attempt to do the work. In addition, using functions and procedures is still hundreds of times faster than carefully crafted SQL statements (one benchmark took over 10 seconds using a WHERE clause, while the function + procedure method took around .12 seconds--note the dot).
Since I am not a mathematician by trade, I found the necessary calculations using Google.
For the "Great Circle Distance" formula, I used Meridian Word Data's website. For the radius finder, I used another that unfortunately I do not have off the top of my head right now. I will look for it again and repost it for proper accreditation.
For the zip code database, I am using the free zip code database from CFDynamics.
Below, you will find the database and table schema, the functions and procedures, and also a demo PHP script to see all of this put into action. As a courtesy, you may download a dump of this database from my website. It's uncompressed size is 3.4M, and it's compressed size is 537K. The checksum is available here.
Please leave me comments, suggestions, questions, and/or rants about this snippet. I feel this is a very useful bit of code, and hope that others out there may find as much use from it as I will be.
5
The resize_image function allows you to resize a GIF, JPEG or PNG file to any dimension you wish and put an optional black border around the image. Here's an explanation of the arguements:
$image_path: The complete path to the image to be resized
$max_width: Maximum width of the resized image. Leave 0 if you want to specify only the height and have the width auto-scale.
$max_height: Maximum height of the resized image. Leave 0 if you want to specify only the width and have the height auto-scale.
$file_prefix: This will prepend a string onto the resized image filename. If you want to create a thumbnail image and keep the original, set $file_prefix = 'thumb'.
$dir: Allows you to save the resized image to a sub directory under the $image_path directory. If you want to save thumbnail images to images/thumbs, set $dir = 'thumbs'.
$border: boolean, 1 = border, 0 = no border
$mime: Image mime type. (image/jpeg, image/gif, image/png)
$image_path: The complete path to the image to be resized
$max_width: Maximum width of the resized image. Leave 0 if you want to specify only the height and have the width auto-scale.
$max_height: Maximum height of the resized image. Leave 0 if you want to specify only the width and have the height auto-scale.
$file_prefix: This will prepend a string onto the resized image filename. If you want to create a thumbnail image and keep the original, set $file_prefix = 'thumb'.
$dir: Allows you to save the resized image to a sub directory under the $image_path directory. If you want to save thumbnail images to images/thumbs, set $dir = 'thumbs'.
$border: boolean, 1 = border, 0 = no border
$mime: Image mime type. (image/jpeg, image/gif, image/png)
13
daysBeteenDates will calculate the number of days between 2 dates in the form of 'YYYY-MM-DD'.
6
Simple file upload script.
5
Open a text file and format it (word wrap).
13
Pagination Class , I think everyone knew now what's it does and means
NT: This class written by my friend have phun!
NT: This class written by my friend have phun!
13
Recursively checks for all *.php and *.tpl files in the directory specified (or the current directory if one is not specified) and runs `php -l $file`. Only outputs the errors.
8
A very simple yet very useful function to have around. Especially generating session codes, filenames or new passwords
-9
By this class you can make a RSS FEED page in your website.









