Archive for category php

Dateiendung ermitteln

< ?php
/**
* Endung der Datei herausfinden
* @param $file Dateiname
* @return mixed var
*/
function getExtension ($file){
$_file=trim("$file");
$getpos=strrpos($_file,".");
if(!$getpos){
		return "";
}
$calc = strlen($_file)-$getpos;
return substr($_file, $getpos+1, $calc);
}
?>

Tags: , , , ,

PHP cache class

< ?php
/**
*
* @var $cache_file_name string file name
* @var $age int age in seconds
*/
class cache {

	public $cache_file_name;
	public $age;

	/**
	* cache::__construct()
	* @access public
	*/
	public function __construct(){
		$this->cache_start();
		register_shutdown_function(array($this, "cache_end"), "inside");
	}

	/**
	* cache::__descruct()
	* @access public
	* @return
	*/
	public function __descruct(){
		$this->cache_end();
	}

	/**
	* cache::cache_start()
	* @access public
	* @return
	*/
	public function cache_start(){

		global $cache_file_name, $age;
		$cache_file_name = 	$_SERVER["DOCUMENT_ROOT"].$_SERVER['REQUEST_URI'] . '_cache';

		if (empty($age)){
			$age = 600;
		}

		if(file_exists($cache_file_name)){
			if (filemtime($cache_file_name) + $age > time()) {
				readfile($cache_file_name);
				unset($cache_file_name);
				exit;
			}
		}
		ob_start();
	}

	/**
	* cache::cache_end()
	* @access public
	* @return
	*/
	public function cache_end()
	{
		global $cache_file_name;
		if (empty($cache_file_name)){
			return;
		}
		$str = ob_get_clean();
		echo $str;
		fwrite(fopen($cache_file_name . '_tmp', "w"), $str);
		rename($cache_file_name . '_tmp',$cache_file_name);
	}

}

?>

Tags: , ,

Doppelte Werte in einem array löschen


function remove_dup($matriz) {
   $aux_ini=array();
   $entrega=array();
   for($n=0;$n<count($matriz);$n++) {
      $aux_ini[]=serialize($matriz[$n]);
   }
   $mat=array_unique($aux_ini);
   for($n=0;$n<count($matriz);$n++) {
      $entrega[]=unserialize($mat[$n]);
   }
   foreach ($entrega as $key => $row){
      if (!is_array($row)) { unset($entrega[$key]); }
   }
   return $entrega;
}

Tags: , , ,

Archives by Subject:

Archives by Month: