Posted By

createinside on 03/31/10


Tagged

String convert filename sanitize


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

BrianCoyDesign


Convert string to filename


 / Published in: PHP
 

Convert/Sanitize the string to a valid filename. The function also replaces the danish characters æøå.

  1. function convert_to_filename ($string) {
  2.  
  3. $string = strtolower($string);
  4.  
  5. $string = str_replace ("ø", "oe", $string);
  6. $string = str_replace ("å", "aa", $string);
  7. $string = str_replace ("æ", "ae", $string);
  8.  
  9. $string = str_replace (" ", "_", $string);
  10. $string = str_replace ("..", ".", $string);
  11.  
  12. preg_replace ("/[^0-9^a-z^_^.]/", "", $string);
  13. return $string;
  14. }

Report this snippet  

You need to login to post a comment.