PHP email validation
2
This is as close to a perfect URL regular expression as I've come. It's based on RFC 3986.
A few caveats:
It only accepts http/https/ftp URLs by design, but you could change that to accept any valid URI pretty easily.
It doesn't support IP-based URLs or authenticated URLs. This is also by design, but you could change that with a little work.
A few caveats:
It only accepts http/https/ftp URLs by design, but you could change that to accept any valid URI pretty easily.
It doesn't support IP-based URLs or authenticated URLs. This is also by design, but you could change that with a little work.
13
daysBeteenDates will calculate the number of days between 2 dates in the form of 'YYYY-MM-DD'.
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)
10
Give this little function a start date and number of days and it will calculate the end date.
28
Create a Thumbnail
12
Another solution recommends using a text match pattern.
This works, but as long as you've got mail.jar in your classpath anyway, you might as well use this technique instead. (Plus, I think it works with older JDK 1.2+, whereas pattern.compile is 1.4+)
Note that it also accepts a comma-separated list of emails, just like a To: or CC: address line would.
This works, but as long as you've got mail.jar in your classpath anyway, you might as well use this technique instead. (Plus, I think it works with older JDK 1.2+, whereas pattern.compile is 1.4+)
Note that it also accepts a comma-separated list of emails, just like a To: or CC: address line would.
15
Generates a tree view within a dropdown select box.
12
Generates select boxes, text boxes, check boxes and radio buttons. Via a handful of functions.
-8
This class is a simple authentication scheme which makes it easy to add authentication to any page by including one class and adding one table to your MySQL database.
The following functions are employed by this authentication class:
auth()
is_authorized()
mysql_bind()
user_create($username,$email,$password)
user_activation_message($username)
user_activation($activation_hash)
user_password_change($username,$password_old,$password_new)
user_logout()
is_username_available( $username )
The following functions are employed by this authentication class:
auth()
this is the default constructor; it automatically checks for the POST vars "username" and "password", it also checks to see if the user passed the GET variable "logout", which would prompt it to set the authentication status to un-authenticated.
is_authorized()
Checks the SESSION variable "authorized" and returns true or false depending on that variable.
mysql_bind()
This is automatically called by the constructor each time the class is instantiated and $_POST['username'] and $_POST['password'] are present. It queries the db for a valid username and MD5 encoded password.
user_create($username,$email,$password)
Creates a user, if the username is available, and creates an MD5 hash based on username, password and date, to be used in the "activation" of the account.
user_activation_message($username)
Sends the custom activation message to the email address for the username specified
user_activation($activation_hash)
Checks to see if the activation hash is valid, if it is, the activation_hash variable is set to NULL, thus signifying that the account is active.
user_password_change($username,$password_old,$password_new)
Quick and easy way to change the user's password with one function call.
user_logout()
Sets the authorization status in $_SESSION['authorized'] to FALSE
is_username_available( $username )
Returns TRUE or FALSE depending on whether or not the username is free.
23
This snippet originally is used for targetting ads banners depended on the geographic location of the visitor, but can be used for other purposes. Also originally is used for US and the rest of the world, but you can add check for other countries too.









