Przeglądaj źródła

Ajout d'une canonicalization plus stricte.

Bastien Sevajol 11 lat temu
rodzic
commit
be363775cf
1 zmienionych plików z 23 dodań i 0 usunięć
  1. 23 0
      src/Muzich/CoreBundle/Util/StrictCanonicalizer.php

+ 23 - 0
src/Muzich/CoreBundle/Util/StrictCanonicalizer.php Wyświetl plik

@@ -46,4 +46,27 @@ class StrictCanonicalizer implements CanonicalizerInterface
46 46
     // On retire les accents occidentaux.
47 47
     return $this->remove_accent($string);
48 48
   }
49
+  
50
+  public function canonicalize_stricter($string)
51
+  {
52
+    $string = $this->canonicalize($string);
53
+    
54
+    // Remove accents from characters
55
+    $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
56
+
57
+    // Everything lowercase
58
+    $string = strtolower($string);
59
+
60
+    // Replace all non-word characters by dashes
61
+    $string = preg_replace("/\W/", "-", $string);
62
+
63
+    // Replace double dashes by single dashes
64
+    $string = preg_replace("/-+/", '-', $string);
65
+
66
+    // Trim dashes from the beginning and end of string
67
+    $string = trim($string, '-');
68
+
69
+    return $string;
70
+  }
71
+  
49 72
 }