Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PHP Filename Bad Character Filter

DZone's Guide to

PHP Filename Bad Character Filter

·
Free Resource
// Function to filter out bad characters in a given filename


function replace_bad_filename_chars($filename) {
  $filtered_filename = "";

  $patterns = array(
    "/\s/", # Whitespace
    "/\&/", # Ampersand
    "/\+/"  # Plus
  );
  $replacements = array(
    "_",   # Whitespace
    "and", # Ampersand
    "plus" # Plus
  );
  
  $filename = preg_replace($patterns,$replacements,$filename);
  for ($i=0;$i
  
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}