You are here

public function FlippingBook::cleanFilename in Flipping Book 8

Helper function to sanitize flipping_book filename.

Parameters

string $filename.: A string representing the file name.

Overrides FlippingBookInterface::cleanFilename

1 call to FlippingBook::cleanFilename()
FlippingBook::prepareExportDirectory in src/FlippingBook.php
Prepare export directory.

File

src/FlippingBook.php, line 123

Class

FlippingBook
Class FlippingBook.

Namespace

Drupal\flipping_book

Code

public function cleanFilename($filename) {

  // Replace whitespace.
  $filename = str_replace(' ', '_', $filename);

  // Remove remaining unsafe characters.
  $filename = preg_replace('![^0-9A-Za-z_.-]!', '', $filename);

  // Remove multiple consecutive non-alphabetical characters.
  $filename = preg_replace('/(_)_+|(\\.)\\.+|(-)-+/', '\\1\\2\\3', $filename);

  // Force lowercase to prevent issues on case-insensitive file systems.
  $filename = strtolower($filename);
  return $filename;
}