Location: PHPKode > projects > phpAWE > phpAWE.0.4.beta.demo-page/awe/utils.php
<?php

function sessionGet($key) {
  return $_SESSION[$key];
}

function sessionSet($key, $value) {
  $_SESSION[$key] = $value;
}

function valueInQuotes ($string, $areola) {
      return $areola.$string.$areola;
}

function tempReplace($old, $new, $string, $areola) {
      return str_replace($areola.$old.$areola, $new, $string);
}

function exArrayShift(&$array) {
      if (is_array($array) && sizeof($array)>1) {          
        $result = array_shift($array);
      } else if (is_array($array)) {
        $result = $array[0];
      } else $result = $array;
      return $result;
}

function massReplace($table, $string, $areola) {
      if (!is_array($table)) return NULL;
      while( list($key, $value) = each($table) ) 
          if (notnumber($key)) {
              $result = tempReplace($key, $value, $string, $areola);
              $string = $result;
          }
              
      
      return $result;
}

function exImplode($separator, $table, $before="", $after="") {
      // based on: mr dot bloar at gmail dot com
      // source: http://pl.php.net/manual/pl/function.implode.php
      $result = $before.$table[0].$after;
      for ($i=1;$i<sizeof($table);$i++) $result .= $separator.$before.$table[$i].$after;
      return $result;
}

function valueOrList($separator, $variable, $before="", $after="") {
      return is_array($variable)?exImplode($separator,$variable,$before,$after):$before.$variable.$after;
}

function notNumber($num) {
      return ereg("^[A-Za-z_][A-Za-z0-9_]*$",(string)$num); 
} 

function textToHtml($text) {
      $text = str_replace("\n","<br/>",$text);
      return $text;
}

function safeFileName($text) {
      if (!strlen($text)) return false; 
        
      $text = strtolower(strtr($text,"ąśżźóę泥ŚŻŹÓŁ ","aszzoeclASZZOECL_"));
      $dot = strrpos($text,".");
      if (!$dot === false) {
      $name = substr($text,0,$dot);
      $extension = substr($text,$dot,strlen($text));
      }
      else $name = $text;
      
      $result[name] = $name;
      $result[extn] = $extension;
      
      return $result;
}

function imageResize($source,$dest,$width=0,$height=0,$quality=75) {
      if (!$width && !$height) return false;
  
      $img_source = @imagecreatefromjpeg($source);
      if ($img_source)
      {
      $xsz_source = imagesx($img_source);
      $ysz_source = imagesy($img_source);
      
      if (!$width) $width = $xsz_source * ($height / $ysz_source);
      if (!$height) $height = $ysz_source * ($width / $xsz_source); 
  
      $img_dest = imagecreatetruecolor($width,$height);
      imagecopyresized($img_dest,$img_source,0,0,0,0,$width,$height,imagesx($img_source),imagesy($img_source));
  
      imagejpeg($img_dest, "$dest", $quality);
      return true;
      }
} 

function deleteFile($file) {
      if (file_exists($file)) unlink($file);
}

function stripHtml($data) {
      // use code posted by: mwwaygoo AT hotmail DOT com
      // source: http://pl.php.net/function.php-strip-whitespace
  
      $data=preg_replace("/(\\t|\\r|\\n)/","",$data);
      $data=preg_replace("/(<![^>]*>)/","",$data);   
      $data=preg_replace('/>\\s</', '><',$data);
  
      return $data;
}


?>
Return current item: phpAWE