Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to limit file name to a given length in PHP?

$
0
0
  1.         /**
  2.          * Limit the File Name Length
  3.          *
  4.          * @access      public
  5.          * @param       string
  6.          * @return      string
  7.          */           
  8.         function limit_filename_length($filename,$length)
  9.         {
  10.                 if(strlen($filename)<$length)
  11.                 {
  12.                         return$filename;
  13.                 }
  14.        
  15.                 $ext='';
  16.                 if(strpos($filename,'.')!==FALSE)
  17.                 {
  18.                         $parts          =explode('.',$filename);
  19.                         $ext            ='.'.array_pop($parts);
  20.                         $filename      =implode('.',$parts);
  21.                 }
  22.        
  23.         returnsubstr($filename,0,($length-strlen($ext))).$ext;
  24.         }

Viewing all articles
Browse latest Browse all 178

Latest Images

Trending Articles



Latest Images