src/AKlump/LoftDataGrids/Exporter.php
protected function filenameSafe($string, $options = array())
    {
        $options += array(
            'extensions' => array('txt', 'md'),
            'ext'        => 'txt',
        );
        $string = preg_replace('/[^a-z0-9\-\.]/', '-', strtolower($string));
        $string = preg_replace('/-{2,}/', '-', $string);

        // Add an extension if not found
        if ($options['ext'] && !preg_match('/\.[a-z]{1,5}$/', $string)) {
            $string .= '.' . trim($options['ext'], '.');
        }

        if ($string && function_exists('file_munge_filename')) {
            $string = file_munge_filename($string, implode(' ', $options['extensions']), false);
        }

        //@todo Add in the module that cleans name if it's installed
        return $string;
    }
protected function filenameSafe($string, $options = array())
    {
        $options += array(
            'extensions' => array('txt', 'md'),
            'ext'        => 'txt',
        );
        $string = preg_replace('/[^a-z0-9\-\.]/', '-', strtolower($string));
        $string = preg_replace('/-{2,}/', '-', $string);

        // Add an extension if not found
        if ($options['ext'] && !preg_match('/\.[a-z]{1,5}$/', $string)) {
            $string .= '.' . trim($options['ext'], '.');
        }

        if ($string && function_exists('file_munge_filename')) {
            $string = file_munge_filename($string, implode(' ', $options['extensions']), false);
        }

        //@todo Add in the module that cleans name if it's installed
        return $string;
    }
protected function filenameSafe ( $ string , $ options = array ( ) ) { $ options += array ( 'extensions' => array ( 'txt' , 'md' ) , 'ext' => 'txt' , ) ; $ string = preg_replace ( '/[^a-z0-9\-\.]/' , '-' , strtolower ( $ string ) ) ; $ string = preg_replace ( '/-{2,}/' , '-' , $ string ) ; // Add an extension if not found if ( $ options [ 'ext' ] && ! preg_match ( '/\.[a-z]{1,5}$/' , $ string ) ) { $ string .= '.' . trim ( $ options [ 'ext' ] , '.' ) ; } if ( $ string && function_exists ( 'file_munge_filename' ) ) { $ string = file_munge_filename ( $ string , implode ( ' ' , $ options [ 'extensions' ] ) , false ) ; } //@todo Add in the module that cleans name if it's installed return $ string ; }
Return a string as a safe filename

@param string $string
The candidtate filename.
@param array  $options
- array extensions: allowable extensions no periods
- string ext: default extension if non found; blank for none no period

@return string
- lowercased, with only letters, numbers, dots and hyphens

@see file_munge_filename().
Return a string as a safe filename