PHP: WonkyMail class for sending email.

Posted on January 10, 2012 by Jimmy K. in Projects, Tutorials.

This class has been four years in the making. It started as a very simple script when someone asked me to create a way to send email messages between users on their website. Over time, more features were added until it ultimately became what it is today. This class presently supports multiple file attachments, multiple [...]

 

PHP: Calculate a person’s age.

Posted on January 9, 2012 by Jimmy K. in Tutorials.

Sometimes you’ll need to calculate an age. It could be the age of a member on your website… It could be your cat. Either way, this can be useful for a variety of reasons such as personalized messages, criteria-based marketing or any functionality that is based on age demographics. I’ve seen a few different versions [...]

 

PHP: Implode an array into a readable format.

Posted on January 9, 2012 by Jimmy K. in Tutorials.

I was recently asked to write a function that implodes a list of items in an array into a human-readable list. For example, [[0] => “Jimmy”, [1] => “Ryan”, [2] => “Ken”, [3] => “Barbie”] would become “Jimmy, Ryan, Ken and Barbie” and [[0] => “apple”, [1] => “banana”] would become “apple and banana”. This [...]

 

PHP: Validate email address format using RegEx.

Posted on January 9, 2012 by Jimmy K. in Tutorials.

Email addresses are used for pretty much everything. Registrations, usernames, lead generation… Everything. They are as unique as a telephone number or physical address and require validation just like any other piece of data. I’ve come across a lot of poorly written email validation scripts, but this one has risen from the ashes in a [...]

 

PHP: Auto-hyperlink URLs using RegEx.

Posted on January 9, 2012 by Jimmy K. in Tutorials.

Have you ever typed a URL into an email or website and a clickable hyperlink was automagically created? Regular expressions, baby! Check it out: This function accepts three arguments; $sInput, $sTarget (optional), and $sClassName (optional). $sInput is the text you would like to search and create hyperlinks for, $sTarget is the target window that hyperlinks [...]

 

PHP: How to truncate characters and words…

Posted on January 9, 2012 by Jimmy K. in Tutorials.

Sometimes you just need to shorten that huge wall of text. Here are two functions that I use frequently to limit the display of lengthy user input: The first function, jTruncate(), truncates text if it is greater than the specified number of characters. For example, if you pass “This is a large block of text!” [...]