This function outputs a string that is filename friendly. It removes all non-characters and punctuation from the input and converts to lowercase. I find this useful for seo friendly cms pages. This function is still being tweaked so any improvements would be most appreciated.

  1. function checkCharacters($title) {
  2.         $final_text = ;
  3.         $title = strtolower(trim(stripslashes($title)));
  4.         for ($i=0;$i<strlen($title);$i++) {
  5.                 $letter = substr($title,$i,1);
  6.                 $ascii = ord($letter);
  7.                 if (($ascii>=97 && $ascii<=122) || ($ascii>=48 && $ascii<=57)) $final_text .= $letter;
  8.                 else $final_text .= "-";
  9.         }
  10.  
  11.         return $final_text;
  12. }