<?php
/*
* Funktions bibliothek
*/
/*
* Unicode Encoder
* encodes a text string in unicode
* useful for mail adresses, cause spam robots can't read them out
* @param string $text text to encode
* @return string $text encoded text
*/
function unicode_encode($text ){
$text=str_replace( "a", "a", $text );#a
$text=str_replace( "b", "b", $text );#b
$text=str_replace( "c", "c", $text );#c
$text=str_replace( "d", "d", $text );#d
$text=str_replace( "e", "e", $text );#e
$text=str_replace( "f", "f", $text );#f
$text=str_replace( "g", "g", $text );#g
$text=str_replace( "h", "h", $text );#h
$text=str_replace( "i", "i", $text );#i
$text=str_replace( "j", "j", $text );#j
$text=str_replace( "k", "k", $text );#k
$text=str_replace( "l", "l", $text );#l
$text=str_replace( "m", "m", $text );#m
$text=str_replace( "n", "n", $text );#n
$text=str_replace( "o", "o", $text );#o
$text=str_replace( "p", "p", $text );#p
$text=str_replace( "q", "q", $text );#q
$text=str_replace( "r", "r", $text );#r
$text=str_replace( "s", "s", $text );#s
$text=str_replace( "t", "t", $text );#t
$text=str_replace( "u", "u", $text );#u
$text=str_replace( "v", "v", $text );#v
$text=str_replace( "w", "w", $text );#w
$text=str_replace( "x", "x", $text );#x
$text=str_replace( "y", "y", $text );#y
$text=str_replace( "z", "z", $text );#z
$text=str_replace( "@", "@", $text );#@
return $text;
}
/*
* Unicode Decoder
* decodes a text string from unicode in text
* useful for mail adresses, cause spam robots can't read them out
* @param string $text text to decode
* @return string $text decoded text
*/
function unicode_decode($text ){
$text=str_replace( "a", "a", $text );#a
$text=str_replace( "b", "b", $text );#b
$text=str_replace( "c", "c", $text );#c
$text=str_replace( "d", "d", $text );#d
$text=str_replace( "e", "e", $text );#e
$text=str_replace( "f", "f", $text );#f
$text=str_replace( "g", "g", $text );#g
$text=str_replace( "h", "h", $text );#h
$text=str_replace( "i", "i", $text );#i
$text=str_replace( "j", "j", $text );#j
$text=str_replace( "k", "k", $text );#k
$text=str_replace( "l", "l", $text );#l
$text=str_replace( "m", "m", $text );#m
$text=str_replace( "n", "n", $text );#n
$text=str_replace( "o", "o", $text );#o
$text=str_replace( "p", "p", $text );#p
$text=str_replace( "q", "q", $text );#q
$text=str_replace( "r", "r", $text );#r
$text=str_replace( "s", "s", $text );#s
$text=str_replace( "t", "t", $text );#t
$text=str_replace( "u", "u", $text );#u
$text=str_replace( "v", "v", $text );#v
$text=str_replace( "w", "w", $text );#w
$text=str_replace( "x", "x", $text );#x
$text=str_replace( "y", "y", $text );#y
$text=str_replace( "z", "z", $text );#z
$text=str_replace( "@", "@", $text );#@
return $text;
}
function getGermanDate($datetime, $convert = 0) {
if(!$convert) {
$datum = substr($datetime,0,10);
$d1 = substr($datum,0,4);
if (strlen($datum) == 8 ) { # date without separators
$d2 = substr($datum,4,2);
$d3 = substr($datum,6,2);
}else{
$d2 = substr($datum,5,2);
$d3 = substr($datum,8,2);
}
$date= $d3.".".$d2.".".$d1;
} else {
$date = substr($datetime,0,10);
$date = explode("-",$date);
$date = $date[2].".".$date[1].".".$date[0];
}
return $date;
}
/*
* Funktion zum kürzen von Text auf eine bestimmte Anzahl Wörter
*
* @param string text
* @param integer zeichen Stringlength
* @param integer kolanz optional, Kolanzwert für Länge
* @param integer punkte optional, Anzahl angehangener Punkte
*/
function word_substr($text, $zeichen, $kolanz=3, $punkte=0) {
$wort = explode(" ",$text);
$newstr = "";
$i = 0;
while(strlen($newstr)<=$zeichen &&
strlen($newstr.$wort[$i])<=($zeichen+$kolanz)) {
$newstr .= $wort[$i]." ";
$i++;
}
if(strlen($text) > $zeichen) {
$newstr .= str_repeat(".",$punkte);
}
return $newstr;
}
function text_columns($text, $columns = 1) {
$textColumns = array();
$length = strlen($text);
$length = ceil($length/$columns);
$words = explode(" ",$text);
$c = count($words);
$l = 0;
for($i=1; $i <= $columns; $i++) {
$new_string = "";
for($g=$l; $g<=$c; $g++) {
if(strlen($new_string) <= $length || $i == $columns) {
$new_string .= $words[$g]." ";
} else {
$l = $g;
break;
}
}
$textColumns[] = $new_string;
}
return $textColumns;
}
// @param text $text
// @param integer $length, default=50
function short_words($text, $length = 50) {
$words = explode(" ",$text);
$count_w = count($words)-1;
if($count_w >= 0) {
for($i=0;$i<=$count_w;$i++) {
if(strlen($words[$i])>=$length) {
$words[$i] = chunk_split($words[$i], $length,"-<br>");
$length = strlen($words[$i])-5;
$words[$i] = substr($words[$i],0,$length);
}
$text = implode(" ",$words);
}
} else {
$text = chunk_split($text,$length,"-<br>");
}
return $text;
}
function fsize($fname) {
$set = 0; $ext = array(" Bytes"," kB","MB","GB","TB");
$objsize = filesize($fname);
while($objsize >= pow(1024,$set)) { ++$set; }
$objsize = round($objsize/pow(1024,$set-1)*100)/100 . $ext[$set-1];
return $objsize;
}
?>