Friday, October 25, 2013

Cleaning Filename

Cleaning Filename

     /**
* Remove spaces and special characters from file names. Swiped this from Drupal.
*/
function clean_filename($name)
{

$special_chars = array ("#","$","%","^","&amp;","*","!","~","‘","\"","’","'","=","?","/","[","]","(",")","|","<",">",";","\\",",",".","&"," ","+",":");


 $replace_chars = array(
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u',
'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f'
);

$name = strtolower($name);

$ext_point = strripos($name,".");


if ($ext_point===false) return false;


$ext = substr($name,$ext_point,strlen($name));


$beforedot = substr($name,0,$ext_point);


$beforedot = str_replace($special_chars, "", $beforedot);  // remove special characters


$beforedot = strtr($beforedot, $replace_chars); // remove Accent characters


/* Limit filename to 50 chars */


 $len=strlen($beforedot);


if($len!=0)
$shortname =substr(trim($beforedot),0,50);

if($len>50)
$shortname=$shortname;

return $shortname.$ext;


}

Public / Private / Protected

Public / Private / Protected

In classes, we attach what is called a visibility to our objects and our methods.
We always have three choices when assigning: public, protected or private. Public
means the class's objects and methods can be accessed by calls from anywhere.
Protected means the objects and methods can only be accessed by methods and
calls which are in the same class tree as the method or object being called. Private
means the methods and objects can only be accessed by the class that the method
or object belongs to.

Including Code From Other Files

Including Code From Other Files

The require construct seen in the example above—in a nutshell—imports the
contents of an external PHP file into our DogTest.php file. It's one of four such
constructs used to include code from other files, each with slightly different behavior:

■ include ― includes the contents of the file. If the file isn't found or is inaccessible,
PHP will issue a warning but will continue executing.

■ include_once ― the same as include, but PHP performs an extra check to
make sure the file hasn't been imported already. If it has, then PHP will not
re-include the contents.

■ require ― similar to include but PHP will stop execution with a fatal error
if the file isn't found.

■ require_once ― the same as require but with an extra check to ensure the
content isn't imported more than once.
Taking