¿Eres nuevo? ¡Lee el FAQ y ponte al día!
845 visitas

Remove the extension from a filename in PHP

This works in all cases I tested, even when the filename has several dots.

PHP
  1. /**
  2.      * Removes the extension from a filename and returns it
  3.      *
  4.      * @param string $original The original filename
  5.      * @return string The file name without the extension
  6.      */
  7.     function removeFilenameExtension($original)
  8.     {
  9.         return preg_replace('/(.+)\..*$/', '$1', $original);
  10.     }
  11.  

­

Etiquetas: PHP strings regex

Insertar: