Handy Functions
Sometimes you need to get the domain name from the page referring to your page... You don't need the whole url/path/page, just the domain... You also don't need/want to worry about the 'www.' at the beginning, that's if of course it's there.... just the domain name...
$justDomain = str_replace('…
A simple function that just helps if you're processing some user generated input and the user seems to have problems using uppercase letters... like for their name, etc....
#
# Quick function to first switch all words to lowercase,
# then capitalise the first letter of each word.
#
function…
Setting values in a config file is a great way to store data in one place, that can be accessed by lots of other pages... and a great way to change things quickly when a site goes live.
However, sometimes you want to store several things that are similar, so an array would be a good idea... This is…
You wouldn't think was so hard, but I often come across this when processing textarea input in a contact form, into the email to the client....
A long story cut short... the solution I found was below:
$msg = '<p>Address: <br />'.str_ireplace(array("\r\n",'\r\n'),'<br />', $…
//
// Convert database date to something more user friendly
//
function userFriendlyDbDate($date){
$time = strtotime($date);
return date('d/m/Y H:i', $time);
}
... and the other way round, so converts to database date format...
//
// Convert date to database date format
//
function…
Email validation is something that is needed in a variety of situations, but I’ve always struggled to find a good one…. Well, here are 2!
The first is something I found online somewhere, and has been modified a little…
$email = '[email protected]';
if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9…
A good logout script is needed in most applications, and here’s the one I use. I have this script in a ‘config’ file that I call at the beginning of every file in the site, so you can logout from any page…
if(isset($_GET['logout'])){ // trigger if ?logout is in the url
$_SESSION = array();
if(…
As the title says
// create a function called for escaping data
function escape_data($data){
$data = ereg_replace("[^A-Za-z0-9]", "",$data);
$data = str_replace('\\','',$data);
$data = strtolower($data);
$data = mysql_escape_string(trim($data));
return $data;
}
//
// Convert a date from jQuery 'Date picker' date to the database date format
//
function dpDateToDbDate($date){
$time = strtotime($date);
return date('Y-m-d', $time);
}
//
// Convert Text to 'Safe Url'
//
// Mark Jacksons Function
function safeURL($txt,$allowSpace=false,$allowCaps=false) {
$find = array('/à|á|â|ã|ä|å/', '/ç/', '/è|é|ê|ë/', '/ì|í|î|ï/', '/ñ/', '/ð|ó|ò|ô|õ|ö|ø/', '/ù|ú|û|ü/', '/ý|ÿ/');
$replace = array('a', 'c', 'e', 'i', 'n', 'o', 'u', 'y…