X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=inc%2Fstring.inc;fp=inc%2Fstring.inc;h=fd370e9757717766bfc130164cd5d0c10aa7c4bb;hb=bc13d5d6e1834068f8b690c32bba114e352dacdd;hp=0000000000000000000000000000000000000000;hpb=07269e54b4e79c0a5e77d8f378cf0849bd8276e5;p=mirrors%2FKyberia-bloodline.git diff --git a/inc/string.inc b/inc/string.inc new file mode 100644 index 0000000..fd370e9 --- /dev/null +++ b/inc/string.inc @@ -0,0 +1,228 @@ + strlen($str_tmp)) { + return $str_tmp; + } + $string_cut = ""; + $threedots_length = 3; + $i = 0; + while (strlen($string_cut)+strlen($StringArray[$i])+$threedots_length < $cut_limit) { + $string_cut .= " " . $StringArray[$i]; + $i++; + } + return ltrim($string_cut) . "..."; + } + } + + function escapeSql($str) { + # single quote ('), double quote ("), backslash (\) and + # NUL (the NULL byte) + $str = addslashes($str); + return $str; + } + + function unescapeSql($str) { + $str = stripslashes($str); + return $str; + } + + function escapeSqlLike($str) { + $str = $this->escapeSql($str); + $str = str_replace('%','\%', $str); + $str = str_replace('_','\_', $str); + return $sql; + } + + function unescapeSqlLike($str) { + $str = $this->unescapeSql($str); + $str = str_replace('\%','%',$str); + $str = str_replace('\_','_',$str); + return $str; + } + + /** + * Recode a string into plain ascii string + * replace czech characters + * + * @param string + * @return a string + */ + function recodeToAscii($string) { + return strtr($string, "áèïéìíòóøšúùýžÁÈÏÉÌÍÒÓ؊ÚÙݎ¹»¾©«®", "acdeeinorstuuyzACDEEINORSTUUYZstzSTZ"); + } + + /* + * winToIso(string) + * isoToWin(string) + * converts czech code pages: Windows CP1250 to Latin ISO-8859-2 + */ + + function winToIso($string) { + return strtr($string,'šžŠŽ','¹»¾©«®'); + } + function isoToWin($string) { + return strtr($string,'¹»¾©«®','šžŠŽ'); + } + + /** + * Next 4 function are for changing case of a string within its coding. + * + * @param string + * @return a string + */ + + function strToUpperCZ($str) { + $str = strtoupper(strtr($str, 'áèïéìíå¾òóøšúùýž¹»¾', 'ÁÈÏÉÌÍżÒÓ؊ÚÙݎ©«®')); + return $str; + } + + function strToUpperCS($str) { + return $this->strToUpperCZ($str); + } + + function strToLowerCZ($str) { + $str = strtolower(strtr($str, 'ÁÈÏÉÌÍżÒÓ؊ÚÙݎ©«®', 'áèïéìíå¾òóøšúùýž¹»¾')); + return $str; + } + + function strToLowerCS($str) { + return $this->strToLowerCZ($str); + } + + function dateToSql($value) { + return (sprintf("%04d-%02d-%02d", $value["year"], $value["mon"], $value["mday"])); + } + + function sqlToDate($value) { + $a["year"]=(int)substr($value,0,4); + $a["mon"]=(int)substr($value,5,2); + $a["mday"]=(int)substr($value,8,2); + return ($a); + } + + function timeToSql($value) { + return (sprintf("%02d:%02d:%02d", $value["hours"], $value["minutes"], $value["seconds"])); + } + + function sqlToTime($value) { + $a["hours"]=(int)substr($value,0,2); + $a["minutes"]=(int)substr($value,3,2); + $a["seconds"]=(int)substr($value,6,2); + return ($a); + } + + function dateTimeToSql($value) { + return (sprintf("%04d-%02d-%02d %02d:%02d:%02d", $value["year"], $value["mon"], $value["mday"], $value["hours"], $value["minutes"], $value["seconds"])); + } + + function sqlToDateTime($value) { + $a["year"]=(int)substr($value,0,4); + $a["mon"]=(int)substr($value,5,2); + $a["mday"]=(int)substr($value,8,2); + $a["hours"]=(int)substr($value,11,2); + $a["minutes"]=(int)substr($value,14,2); + $a["seconds"]=(int)substr($value,17,2); + return ($a); + } + + function sqlToUnix($value) { + $dt = $this->sqlToDateTime($value); + return mktime($dt['hours'], $dt['minutes'], $dt['seconds'], + $dt['mon'], $dt['mday'], $dt['year']); + } + + function czTime($value, $seconds=TRUE) { + if ($seconds) { + return sprintf("%d:%02d:%02d", $value['hours'], $value['minutes'], + $value['seconds']); + } + else { + return sprintf("%d:%02d", $value['hours'], $value['minutes']); + } + } + + function czDate($value) { + return sprintf("%d.%d.%d", $value['mday'], $value['mon'], + $value['year']); + } + + function encodeString($string) { + for ($i = 0;$i < strlen($string);$i++) { + $ch = substr($string,$i,1); + $ch = ord($ch)+100; + $encoded_string .= dechex($ch); + } + return $encoded_string; + } + + function decodeString($string) { + for ($i = 0;$i < strlen($string);$i += 2) { + $ch = substr($string,$i,2); + $ch = hexdec($ch); + $ch -= 100; + $decode_string .= chr($ch); + } + return $decode_string; + } +} +?>