<?php

function getMimeType($file)
{
	$ret = "url";
	if(preg_match("/.jpg|.jpeg/i",$file)) return "image/jpeg";
	if(preg_match("/.gif/i",$file)) return "image/gif";
	if(preg_match("/.pdf/i",$file)) return "application/pdf";
	if(preg_match("/.htm/i",$file)) return "text/html";
	if(preg_match("/.txt|.doc|.text/i",$file)) return "text/plain";
	return $ret;
}

function fixString($value)
{
	global $_utf8_encode;
	if($value[0]=='\"') $value[0]="";
	if($value[strlen($value)-1]=='\"') $value[strlen($value)-1]="";
	$value = str_replace("<!NL>","\n",$value);
	$value = str_replace("&","&amp;",$value);
	$value = str_replace("<","&lt;",$value);
	$value = str_replace(">","&gt;",$value);
	$value = str_replace("\"","&quot;",$value);
	
	//if($_utf8_encode)
		//$value = utf8_encode($value);
	//$value = utf8_decode($value);
	//return trim( iconv( "UTF-16", "UTF-8", $value) );
	return trim( $value );
}

function formatNumber($value)
{
	str_replace(",",".",$value);
	return str_replace(",",".",$value);
}

function convertDate($date)
{
	if(preg_match("/(\d{4})\D(\d{2})\D(\d{2})/",$date,$t))
	{
		return $t[1] . "-" . $t[2] . "-" . $t[3];
	}
	if(preg_match("/(\d{2})\D(\d{2})\D(\d{4})/",$date,$t))
	{
		return $t[3] . "-" . $t[2] . "-" . $t[1];
	}
	if(preg_match("/(\d{2})\D(\d{2})\D(\d{2})/",$date,$t))
	{
		return "20" . $t[3] . "-" . $t[2] . "-" . $t[1];
	}
}
?>
