Location: PHPKode > projects > Content*Builder > libraries/BTPL_functions.inc.php
<?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", "&#97;",  $text );#a
	$text=str_replace( "b", "&#98;",  $text );#b
	$text=str_replace( "c", "&#99;",  $text );#c
	$text=str_replace( "d", "&#100;", $text );#d
	$text=str_replace( "e", "&#101;", $text );#e
	$text=str_replace( "f", "&#102;", $text );#f
	$text=str_replace( "g", "&#103;", $text );#g
	$text=str_replace( "h", "&#104;", $text );#h
	$text=str_replace( "i", "&#105;", $text );#i
	$text=str_replace( "j", "&#106;", $text );#j
	$text=str_replace( "k", "&#107;", $text );#k
	$text=str_replace( "l", "&#108;", $text );#l
	$text=str_replace( "m", "&#109;", $text );#m
	$text=str_replace( "n", "&#110;", $text );#n
	$text=str_replace( "o", "&#111;", $text );#o
	$text=str_replace( "p", "&#112;", $text );#p
	$text=str_replace( "q", "&#113;", $text );#q
	$text=str_replace( "r", "&#114;", $text );#r
	$text=str_replace( "s", "&#115;", $text );#s
	$text=str_replace( "t", "&#116;", $text );#t
	$text=str_replace( "u", "&#117;", $text );#u
	$text=str_replace( "v", "&#118;", $text );#v
	$text=str_replace( "w", "&#119;", $text );#w
	$text=str_replace( "x", "&#120;", $text );#x
	$text=str_replace( "y", "&#121;", $text );#y
	$text=str_replace( "z", "&#122;", $text );#z
	$text=str_replace( "@", "&#64;",  $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( "&#97;",  "a", $text );#a
	$text=str_replace( "&#98;",  "b", $text );#b
	$text=str_replace( "&#99;",  "c", $text );#c
	$text=str_replace( "&#100;", "d", $text );#d
	$text=str_replace( "&#101;", "e", $text );#e
	$text=str_replace( "&#102;", "f", $text );#f
	$text=str_replace( "&#103;", "g", $text );#g
	$text=str_replace( "&#104;", "h", $text );#h
	$text=str_replace( "&#105;", "i", $text );#i
	$text=str_replace( "&#106;", "j", $text );#j
	$text=str_replace( "&#107;", "k", $text );#k
	$text=str_replace( "&#108;", "l", $text );#l
	$text=str_replace( "&#109;", "m", $text );#m
	$text=str_replace( "&#110;", "n", $text );#n
	$text=str_replace( "&#111;", "o", $text );#o
	$text=str_replace( "&#112;", "p", $text );#p
	$text=str_replace( "&#113;", "q", $text );#q
	$text=str_replace( "&#114;", "r", $text );#r
	$text=str_replace( "&#115;", "s", $text );#s
	$text=str_replace( "&#116;", "t", $text );#t
	$text=str_replace( "&#117;", "u", $text );#u
	$text=str_replace( "&#118;", "v", $text );#v
	$text=str_replace( "&#119;", "w", $text );#w
	$text=str_replace( "&#120;", "x", $text );#x
	$text=str_replace( "&#121;", "y", $text );#y
	$text=str_replace( "&#122;", "z", $text );#z
	$text=str_replace( "&#64;",  "@", $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;
}
?>
Return current item: Content*Builder