strip punctuation
1 2 preg_replace('/[^a-zA-Z0-9-\s]/', '', "TAGholy! moley. & bat's were killed ^% by ; dogs, for £50");
12970 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 preg_replace('/[^a-zA-Z0-9-\s]/', '', "TAGholy! moley. & bat's were killed ^% by ; dogs, for £50");
1 2 function time_since($original) { 3 // array of time period chunks 4 $chunks = array( 5 array(60 * 60 * 24 * 365 , 'year'), 6 array(60 * 60 * 24 * 30 , 'month'), 7 array(60 * 60 * 24 * 7, 'week'), 8 array(60 * 60 * 24 , 'day'), 9 array(60 * 60 , 'hour'), 10 array(60 , 'minute'), 11 ); 12 13 $today = time(); /* Current unix time */ 14 $since = $today - $original; 15 16 if($since > 604800) { 17 $print = date("M jS", $original); 18 19 if($since > 31536000) { 20 $print .= ", " . date("Y", $original); 21 } 22 23 return $print; 24 25 } 26 27 // $j saves performing the count function each time around the loop 28 for ($i = 0, $j = count($chunks); $i < $j; $i++) { 29 30 $seconds = $chunks[$i][0]; 31 $name = $chunks[$i][1]; 32 33 // finding the biggest chunk (if the chunk fits, break) 34 if (($count = floor($since / $seconds)) != 0) { 35 // DEBUG print "<!-- It's $name -->\n"; 36 break; 37 } 38 } 39 40 $print = ($count == 1) ? '1 '.$name : "$count {$name}s"; 41 42 return $print . " ago"; 43 44 }