483 unset($needed_parts[$m[1]]); |
472 unset($needed_parts[$m[1]]); |
484 } |
473 } |
485 |
474 |
486 return $needed_parts ? false : $data; |
475 return $needed_parts ? false : $data; |
487 } |
476 } |
|
477 |
|
478 /** |
|
479 * Modifies a string to remove all non ASCII characters and spaces. |
|
480 */ |
|
481 function slugify($text) |
|
482 { |
|
483 // replace non letter or digits by - |
|
484 $text = preg_replace('~[^\\pL\d]+~u', '-', $text); |
|
485 |
|
486 // trim |
|
487 $text = trim($text, '-'); |
|
488 |
|
489 // transliterate |
|
490 if (function_exists('iconv')) |
|
491 { |
|
492 $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); |
|
493 } |
|
494 |
|
495 // lowercase |
|
496 $text = strtolower($text); |
|
497 |
|
498 // remove unwanted characters |
|
499 $text = preg_replace('~[^-\w]+~', '', $text); |
|
500 |
|
501 if (empty($text)) |
|
502 { |
|
503 return 'n-a'; |
|
504 } |
|
505 |
|
506 return $text; |
|
507 } |
|
508 |
|
509 |
|
510 // from http://www.house6.com/blog/?p=83 |
|
511 function sanitize_filename($f) { |
|
512 // a combination of various methods |
|
513 // we don't want to convert html entities, or do any url encoding |
|
514 // we want to retain the "essence" of the original file name, if possible |
|
515 // char replace table found at: |
|
516 // http://www.php.net/manual/en/function.strtr.php#98669 |
|
517 $replace_chars = array( |
|
518 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', |
|
519 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', |
|
520 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', |
|
521 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', |
|
522 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', |
|
523 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', |
|
524 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f' |
|
525 ); |
|
526 $f = strtr($f, $replace_chars); |
|
527 // convert & to "and", @ to "at", and # to "number" |
|
528 $f = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/'), array('-and-', '-at-', '-number-'), $f); |
|
529 $f = preg_replace('/[^(\x20-\x7F)]*/','', $f); // removes any special chars we missed |
|
530 $f = str_replace(' ', '-', $f); // convert space to hyphen |
|
531 $f = str_replace('\'', '', $f); // removes apostrophes |
|
532 $f = preg_replace('/[^\w\-\.]+/', '', $f); // remove non-word chars (leaving hyphens and periods) |
|
533 $f = preg_replace('/[\-]+/', '-', $f); // converts groups of hyphens into one |
|
534 if (function_exists('iconv')) |
|
535 { |
|
536 $f = iconv('utf-8', 'us-ascii//TRANSLIT', $f); |
|
537 } |
|
538 |
|
539 return strtolower($f); |
|
540 } |