YannBergonzat

Accents, épisode 2

Jun 17th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.     private function friendly_filename($str) {
  3.         // everything to lower and no spaces begin or end
  4.         $str = strtolower(trim($str));
  5.  
  6.         //replace accent characters, depends your language is needed
  7.         $str=$this->replace_accents($str);
  8.  
  9.         // decode html maybe needed if there's html I normally don't use this
  10.         //$str = html_entity_decode($str,ENT_QUOTES,'UTF8');
  11.  
  12.         $str = escapeshellarg($str);
  13.  
  14.         // adding - for spaces and union characters
  15.         $find = array(' ', '&', '\r\n', '\n', '+',',');
  16.         $str = str_replace ($find, '_', $str);
  17.  
  18.         //delete and replace rest of special chars
  19.         $find = array('/[^a-z0-9\-\.<>]/', '/[\-]+/', '/<[^>]*>/');
  20.         $repl = array('', '-', '');
  21.         $str = preg_replace ($find, $repl, $str);
  22.  
  23.         //return the friendly str
  24.         return $str;
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment