1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | /*-------------------- string helper -----------------------*/ function str_truncate($text,$numb) { $text = html_entity_decode($text, ENT_QUOTES); if (strlen($text) > $numb) { $text = substr($text, 0, $numb); $text = substr($text,0,strrpos($text," ")); //This strips the full stop: if ((substr($text, -1)) == ".") { $text = substr($text,0,(strrpos($text,"."))); } $etc = "..."; $text = $text.$etc; } $text = htmlentities($text, ENT_QUOTES); return $text; } // highlight errors function str_flash($text,$color=null) { if (preg_match("/error/i", $text) || preg_match("/warning/i", $text)) $color = '#FFCACA'; else $color = 'yellow'; $temp_text = '<div style="background:'.$color.'; color:black;">'.$text.'</div>'; return $temp_text; } function str_break ($astring) { $astring = str_replace(chr(13) . chr(10), "<br />", $astring); return $astring; } /*-------------------- date/time helper -----------------------*/ // change date format from dd/mm/yyyy to yyyy-mm-dd function date_human_sql($adate) { $tmpdate = explode ("/",$adate); $newdate = $tmpdate[2]."-".$tmpdate[1]."-".$tmpdate[0]; return $newdate; } // change date format from yyyy-mm-dd to dd/mm/yyyy function date_sql_human($adate) { if ($adate != '' && $adate != '0000-00-00') { $tmpdate = explode ("-",$adate); $newdate = $tmpdate[2]."/".$tmpdate[1]."/".$tmpdate[0]; } else { $newdate = ''; } return $newdate; } // get difference between 2 date - in days function date_differ($dformat, $endDate, $beginDate) { // datediff = - (dash) should be in Y-m-d format $date_parts1=explode($dformat, $beginDate); $date_parts2=explode($dformat, $endDate); $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]); $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]); return $end_date - $start_date; } // change datetime format from yyyy-mm-dd 00:00:00 to yyyy/mm/dd function date_short($adate) { $newdate = substr($adate, 0, 10); return $newdate; } // change datetime format from yyyy-mm-dd 00:00:00 to 00:00:00 function time_short($adatetime) { $newtime = substr($adatetime, 10, 10); return $newtime; } /*-------------------- number helper -----------------------*/ // format figure to xx,xxx.xx function number_currency($float) { return number_format($float,2,".",","); } |